diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-11-07 06:49:40 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-11-07 06:49:40 +0100 |
| commit | 37bf3835b0b3ce7f4c80924f40735698f057ef6f (patch) | |
| tree | 5862a10eef97cf3575bfe55b2f29fc5a79ae3270 /src/drivers | |
| parent | b663e272e7f39063a5c1bf744038ded0a7566990 (diff) | |
Create class Fl_Unix_Screen_Driver used by X11 and Wayland platforms
Diffstat (limited to 'src/drivers')
21 files changed, 395 insertions, 215 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H index 83cf5feb0..fbd76b68e 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H @@ -102,6 +102,10 @@ public: virtual int clipboard_contains(const char *type); virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); virtual void reset_spot(); + virtual int need_menu_handle_part2() {return 1;} + // these 2 are in Fl_get_key_mac.cxx + virtual int event_key(int); + virtual int get_key(int); private: float scale_; }; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx index 33b0392c4..b955c0a97 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx @@ -35,6 +35,47 @@ extern void (*fl_unlock_function)(); int Fl_Cocoa_Screen_Driver::next_marked_length = 0; +// This key table is used for the Darwin system driver. It is defined here +// "static" and assigned in the constructor to avoid static initialization +// race conditions. It is used in fl_shortcut.cxx. +// +// This table must be in numeric order by fltk (X) keysym number: + +Fl_Screen_Driver::Keyname darwin_key_table[] = { + // v - this column may contain UTF-8 characters + {' ', "Space"}, + {FL_BackSpace, "⌫"/*"\xe2\x8c\xab"*/}, // U+232B : erase to the left + {FL_Tab, "⇥"/*"\xe2\x87\xa5"*/}, // U+21E5 rightwards arrow to bar + {FL_Enter, "↩"/*"\xe2\x86\xa9"*/}, // U+21A9 leftwards arrow with hook + {FL_Pause, "Pause"}, + {FL_Scroll_Lock, "Scroll_Lock"}, + {FL_Escape, "⎋"/*"\xe2\x8e\x8b"*/}, // U+238B : broken circle with northwest arrow + {FL_Home, "↖"/*"\xe2\x86\x96"*/}, // U+2196 north west arrow + {FL_Left, "←"/*"\xe2\x86\x90"*/}, // U+2190 leftwards arrow + {FL_Up, "↑"/*"\xe2\x86\x91"*/}, // U+2191 upwards arrow + {FL_Right, "→"/*"\xe2\x86\x92"*/}, // U+2192 rightwards arrow + {FL_Down, "↓"/*"\xe2\x86\x93"*/}, // U+2193 downwards arrow + {FL_Page_Up, "⇞"/*"\xe2\x87\x9e"*/}, // U+21DE upwards arrow with double stroke + {FL_Page_Down, "⇟"/*"\xe2\x87\x9f"*/}, // U+21DF downwards arrow with double stroke + {FL_End, "↘"/*"\xe2\x86\x98"*/}, // U+2198 south east arrow + {FL_Print, "Print"}, + {FL_Insert, "Insert"}, + {FL_Menu, "Menu"}, + {FL_Num_Lock, "Num_Lock"}, + {FL_KP_Enter, "⌤"/*"\xe2\x8c\xa4"*/}, // U+2324 up arrow head between two horizontal bars + {FL_Shift_L, "Shift_L"}, + {FL_Shift_R, "Shift_R"}, + {FL_Control_L, "Control_L"}, + {FL_Control_R, "Control_R"}, + {FL_Caps_Lock, "⇪"/*"\xe2\x87\xaa"*/}, // U+21EA upwards white arrow from bar + {FL_Meta_L, "Meta_L"}, + {FL_Meta_R, "Meta_R"}, + {FL_Alt_L, "Alt_L"}, + {FL_Alt_R, "Alt_R"}, + {FL_Delete, "⌦"/*"\xe2\x8c\xa6"*/} // U+2326 : erase to the right +}; + + static Fl_Text_Editor::Key_Binding extra_bindings[] = { // Define CMD+key accelerators... { 'z', FL_COMMAND, Fl_Text_Editor::kf_undo ,0}, @@ -58,6 +99,9 @@ Fl_Cocoa_Screen_Driver::Fl_Cocoa_Screen_Driver() { text_editor_extra_key_bindings = extra_bindings; scale_ = 1.; default_icon = nil; + // initialize key table + key_table = darwin_key_table; + key_table_size = sizeof(darwin_key_table)/sizeof(*darwin_key_table); } diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.H b/src/drivers/Darwin/Fl_Darwin_System_Driver.H index 262f782df..4113424ca 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.H +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.H @@ -51,9 +51,6 @@ public: static int calc_mac_os_version(); // computes the fl_mac_os_version global variable static unsigned short *compute_macKeyLookUp(); - // these 2 are in Fl_get_key_mac.cxx - virtual int event_key(int k); - virtual int get_key(int k); virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **), char *errmsg=NULL, int errmsg_sz=0); diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx index bda6667e8..2d1e4d4e4 100644 --- a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx +++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx @@ -35,45 +35,6 @@ #include <sys/mount.h> #include <sys/stat.h> -// This key table is used for the Darwin system driver. It is defined here -// "static" and assigned in the constructor to avoid static initialization -// race conditions. It is used in fl_shortcut.cxx. -// -// This table must be in numeric order by fltk (X) keysym number: - -Fl_System_Driver::Keyname darwin_key_table[] = { - // v - this column may contain UTF-8 characters - {' ', "Space"}, - {FL_BackSpace, "⌫"/*"\xe2\x8c\xab"*/}, // U+232B : erase to the left - {FL_Tab, "⇥"/*"\xe2\x87\xa5"*/}, // U+21E5 rightwards arrow to bar - {FL_Enter, "↩"/*"\xe2\x86\xa9"*/}, // U+21A9 leftwards arrow with hook - {FL_Pause, "Pause"}, - {FL_Scroll_Lock, "Scroll_Lock"}, - {FL_Escape, "⎋"/*"\xe2\x8e\x8b"*/}, // U+238B : broken circle with northwest arrow - {FL_Home, "↖"/*"\xe2\x86\x96"*/}, // U+2196 north west arrow - {FL_Left, "←"/*"\xe2\x86\x90"*/}, // U+2190 leftwards arrow - {FL_Up, "↑"/*"\xe2\x86\x91"*/}, // U+2191 upwards arrow - {FL_Right, "→"/*"\xe2\x86\x92"*/}, // U+2192 rightwards arrow - {FL_Down, "↓"/*"\xe2\x86\x93"*/}, // U+2193 downwards arrow - {FL_Page_Up, "⇞"/*"\xe2\x87\x9e"*/}, // U+21DE upwards arrow with double stroke - {FL_Page_Down, "⇟"/*"\xe2\x87\x9f"*/}, // U+21DF downwards arrow with double stroke - {FL_End, "↘"/*"\xe2\x86\x98"*/}, // U+2198 south east arrow - {FL_Print, "Print"}, - {FL_Insert, "Insert"}, - {FL_Menu, "Menu"}, - {FL_Num_Lock, "Num_Lock"}, - {FL_KP_Enter, "⌤"/*"\xe2\x8c\xa4"*/}, // U+2324 up arrow head between two horizontal bars - {FL_Shift_L, "Shift_L"}, - {FL_Shift_R, "Shift_R"}, - {FL_Control_L, "Control_L"}, - {FL_Control_R, "Control_R"}, - {FL_Caps_Lock, "⇪"/*"\xe2\x87\xaa"*/}, // U+21EA upwards white arrow from bar - {FL_Meta_L, "Meta_L"}, - {FL_Meta_R, "Meta_R"}, - {FL_Alt_L, "Alt_L"}, - {FL_Alt_R, "Alt_R"}, - {FL_Delete, "⌦"/*"\xe2\x8c\xa6"*/} // U+2326 : erase to the right -}; const char *Fl_Darwin_System_Driver::shift_name() { return "⇧\\"; // "\xe2\x87\xa7\\"; // U+21E7 (upwards white arrow) @@ -90,9 +51,6 @@ const char *Fl_Darwin_System_Driver::control_name() { Fl_Darwin_System_Driver::Fl_Darwin_System_Driver() : Fl_Posix_System_Driver() { if (fl_mac_os_version == 0) fl_mac_os_version = calc_mac_os_version(); - // initialize key table - key_table = darwin_key_table; - key_table_size = sizeof(darwin_key_table)/sizeof(*darwin_key_table); command_key = FL_META; control_key = FL_CTRL; } diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx index 6795fb06b..5a4d5ada7 100644 --- a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx @@ -23,6 +23,7 @@ Fl_GDI_Image_Surface_Driver::Fl_GDI_Image_Surface_Driver(int w, int h, int high_res, Fl_Offscreen off) : Fl_Image_Surface_Driver(w, h, high_res, off) { + Fl_Display_Device::display_device(); // make sure fl_graphics_driver was initialized float d = fl_graphics_driver->scale(); if (!off && d != 1 && high_res) { w = int(w*d); diff --git a/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx b/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx index 653ab4a9a..cdd77385c 100644 --- a/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx +++ b/src/drivers/Posix/Fl_Posix_Printer_Driver.cxx @@ -35,7 +35,7 @@ class Fl_Posix_Printer_Driver : public Fl_PostScript_File_Device { #include <dlfcn.h> // for dlopen et al #include <unistd.h> // for mkstemp #include <FL/filename.H> -#include "../X11/Fl_X11_System_Driver.H" +#include "../Unix/Fl_Unix_System_Driver.H" #define GTK_PAPER_NAME_LETTER "na_letter" #define GTK_RESPONSE_NONE 0 #define GTK_RESPONSE_OK -5 diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H index ec9439faa..df9407c17 100644 --- a/src/drivers/Posix/Fl_Posix_System_Driver.H +++ b/src/drivers/Posix/Fl_Posix_System_Driver.H @@ -64,7 +64,6 @@ public: virtual int rmdir(const char* f) {return ::rmdir(f);} virtual int rename(const char* f, const char *n) {return ::rename(f, n);} virtual const char *getpwnam(const char *login); - virtual int need_menu_handle_part2() {return 1;} #if HAVE_DLFCN_H virtual void *load(const char *filename); #if HAVE_DLSYM diff --git a/src/drivers/Unix/Fl_Unix_Screen_Driver.H b/src/drivers/Unix/Fl_Unix_Screen_Driver.H new file mode 100644 index 000000000..ebd0ed706 --- /dev/null +++ b/src/drivers/Unix/Fl_Unix_Screen_Driver.H @@ -0,0 +1,61 @@ +// +// Definition of the part of the screen driver shared by X11 and Wayland platforms +// for the Fast Light Tool Kit (FLTK). +// +// Copyright 2021-2022 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#ifndef FL_UNIX_SCREEN_DRIVER_H +#define FL_UNIX_SCREEN_DRIVER_H + +#include "../../Fl_Screen_Driver.H" + +# if USE_POLL + +# include <poll.h> +static pollfd *pollfds = 0; + +# else +# if HAVE_SYS_SELECT_H +# include <sys/select.h> +# endif /* HAVE_SYS_SELECT_H */ + +// The following #define is only needed for HP-UX 9.x and earlier: +//#define select(a,b,c,d,e) select((a),(int *)(b),(int *)(c),(int *)(d),(e)) + +# define POLLIN 1 +# define POLLOUT 4 +# define POLLERR 8 + +# endif /* USE_POLL */ + + +class Fl_Unix_Screen_Driver : public Fl_Screen_Driver { +public: + static fd_set fdsets[3]; + static int maxfd; + static int nfds; + static struct FD { + # if !USE_POLL + int fd; + short events; + # endif + void (*cb)(int, void*); + void* arg; + } *fd; + virtual int poll_or_select_with_delay(double time_to_wait); + virtual int poll_or_select(); + virtual void *control_maximize_button(void *) { return NULL; } +}; + +#endif /* FL_UNIX_SCREEN_DRIVER_H */ diff --git a/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx b/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx new file mode 100644 index 000000000..0b33b0a20 --- /dev/null +++ b/src/drivers/Unix/Fl_Unix_Screen_Driver.cxx @@ -0,0 +1,96 @@ +// +// Definition of the part of the Screen interface shared by X11/Wayland +// +// Copyright 2022 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#include <config.h> +#include "Fl_Unix_Screen_Driver.H" + +fd_set Fl_Unix_Screen_Driver::fdsets[3]; +int Fl_Unix_Screen_Driver::maxfd = 0; +int Fl_Unix_Screen_Driver::nfds = 0; +Fl_Unix_Screen_Driver::FD *Fl_Unix_Screen_Driver::fd = NULL; + +// these pointers are set by the Fl::lock() function: +static void nothing() {} +void (*fl_lock_function)() = nothing; +void (*fl_unlock_function)() = nothing; + + +// This is never called with time_to_wait < 0.0: +// It should return negative on error, 0 if nothing happens before +// timeout, and >0 if any callbacks were done. +int Fl_Unix_Screen_Driver::poll_or_select_with_delay(double time_to_wait) { +# if !USE_POLL + fd_set fdt[3]; + fdt[0] = fdsets[0]; + fdt[1] = fdsets[1]; + fdt[2] = fdsets[2]; +# endif + int n; + + fl_unlock_function(); + + if (time_to_wait < 2147483.648) { +# if USE_POLL + n = ::poll(pollfds, nfds, int(time_to_wait*1000 + .5)); +# else + timeval t; + t.tv_sec = int(time_to_wait); + t.tv_usec = int(1000000 * (time_to_wait-t.tv_sec)); + n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); +# endif + } else { +# if USE_POLL + n = ::poll(pollfds, nfds, -1); +# else + n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],0); +# endif + } + + fl_lock_function(); + + if (n > 0) { + for (int i=0; i<nfds; i++) { +# if USE_POLL + if (pollfds[i].revents) fd[i].cb(pollfds[i].fd, fd[i].arg); +# else + int f = fd[i].fd; + short revents = 0; + if (FD_ISSET(f,&fdt[0])) revents |= POLLIN; + if (FD_ISSET(f,&fdt[1])) revents |= POLLOUT; + if (FD_ISSET(f,&fdt[2])) revents |= POLLERR; + if (fd[i].events & revents) fd[i].cb(f, fd[i].arg); +# endif + } + } + return n; +} + + +int Fl_Unix_Screen_Driver::poll_or_select() { + if (!nfds) return 0; // nothing to select or poll +# if USE_POLL + return ::poll(pollfds, nfds, 0); +# else + timeval t; + t.tv_sec = 0; + t.tv_usec = 0; + fd_set fdt[3]; + fdt[0] = fdsets[0]; + fdt[1] = fdsets[1]; + fdt[2] = fdsets[2]; + return ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); +# endif +} diff --git a/src/drivers/Unix/Fl_Unix_System_Driver.H b/src/drivers/Unix/Fl_Unix_System_Driver.H index 60f300d33..7234cc360 100644 --- a/src/drivers/Unix/Fl_Unix_System_Driver.H +++ b/src/drivers/Unix/Fl_Unix_System_Driver.H @@ -44,10 +44,6 @@ public: virtual void remove_fd(int); double wait(double time_to_wait); int ready(); - // 3 additional virtual members - virtual int poll_or_select_with_delay(double time_to_wait); - virtual int poll_or_select(); - virtual void *control_maximize_button(void *data); static unsigned char *create_bmp(const unsigned char *data, int W, int H, int *return_size); static Fl_RGB_Image *own_bmp_to_RGB(char *bmp); static void read_int(uchar *c, int& i); diff --git a/src/drivers/Unix/Fl_Unix_System_Driver.cxx b/src/drivers/Unix/Fl_Unix_System_Driver.cxx index 628307c73..1efe01b0a 100644 --- a/src/drivers/Unix/Fl_Unix_System_Driver.cxx +++ b/src/drivers/Unix/Fl_Unix_System_Driver.cxx @@ -16,6 +16,7 @@ // #include "Fl_Unix_System_Driver.H" +#include "Fl_Unix_Screen_Driver.H" #include <FL/Fl_File_Browser.H> #include <FL/fl_string_functions.h> // fl_strdup #include <FL/platform.H> @@ -641,55 +642,22 @@ const char *Fl_Unix_System_Driver::filename_name(const char *name) { } -//////////////////////////////////////////////////////////////// -// interface to poll/select call: - -# if USE_POLL - -# include <poll.h> -static pollfd *pollfds = 0; - -# else -# if HAVE_SYS_SELECT_H -# include <sys/select.h> -# endif /* HAVE_SYS_SELECT_H */ - -// The following #define is only needed for HP-UX 9.x and earlier: -//#define select(a,b,c,d,e) select((a),(int *)(b),(int *)(c),(int *)(d),(e)) - -static fd_set fdsets[3]; -static int maxfd; -# define POLLIN 1 -# define POLLOUT 4 -# define POLLERR 8 - -# endif /* USE_POLL */ - -static int nfds = 0; static int fd_array_size = 0; -struct FD { -# if !USE_POLL - int fd; - short events; -# endif - void (*cb)(int, void*); - void* arg; -}; - -static FD *fd = 0; void Fl_Unix_System_Driver::add_fd(int n, int events, void (*cb)(int, void*), void *v) { remove_fd(n,events); - int i = nfds++; + int i = Fl_Unix_Screen_Driver::nfds++; if (i >= fd_array_size) { - FD *temp; + Fl_Unix_Screen_Driver::FD *temp; fd_array_size = 2*fd_array_size+1; - if (!fd) temp = (FD*)malloc(fd_array_size*sizeof(FD)); - else temp = (FD*)realloc(fd, fd_array_size*sizeof(FD)); + if (!Fl_Unix_Screen_Driver::fd) temp = + (Fl_Unix_Screen_Driver::FD*)malloc(fd_array_size*sizeof(Fl_Unix_Screen_Driver::FD)); + else temp = (Fl_Unix_Screen_Driver::FD*)realloc(Fl_Unix_Screen_Driver::fd, + fd_array_size*sizeof(Fl_Unix_Screen_Driver::FD)); if (!temp) return; - fd = temp; + Fl_Unix_Screen_Driver::fd = temp; # if USE_POLL pollfd *tpoll; @@ -701,18 +669,18 @@ void Fl_Unix_System_Driver::add_fd(int n, int events, void (*cb)(int, void*), vo pollfds = tpoll; # endif } - fd[i].cb = cb; - fd[i].arg = v; + Fl_Unix_Screen_Driver::fd[i].cb = cb; + Fl_Unix_Screen_Driver::fd[i].arg = v; # if USE_POLL pollfds[i].fd = n; pollfds[i].events = events; # else - fd[i].fd = n; - fd[i].events = events; - if (events & POLLIN) FD_SET(n, &fdsets[0]); - if (events & POLLOUT) FD_SET(n, &fdsets[1]); - if (events & POLLERR) FD_SET(n, &fdsets[2]); - if (n > maxfd) maxfd = n; + Fl_Unix_Screen_Driver::fd[i].fd = n; + Fl_Unix_Screen_Driver::fd[i].events = events; + if (events & POLLIN) FD_SET(n, &Fl_Unix_Screen_Driver::fdsets[0]); + if (events & POLLOUT) FD_SET(n, &Fl_Unix_Screen_Driver::fdsets[1]); + if (events & POLLERR) FD_SET(n, &Fl_Unix_Screen_Driver::fdsets[2]); + if (n > Fl_Unix_Screen_Driver::maxfd) Fl_Unix_Screen_Driver::maxfd = n; # endif } @@ -723,9 +691,9 @@ void Fl_Unix_System_Driver::add_fd(int n, void (*cb)(int, void*), void* v) { void Fl_Unix_System_Driver::remove_fd(int n, int events) { int i,j; # if !USE_POLL - maxfd = -1; // recalculate maxfd on the fly + Fl_Unix_Screen_Driver::maxfd = -1; // recalculate maxfd on the fly # endif - for (i=j=0; i<nfds; i++) { + for (i=j=0; i<Fl_Unix_Screen_Driver::nfds; i++) { # if USE_POLL if (pollfds[i].fd == n) { int e = pollfds[i].events & ~events; @@ -733,27 +701,27 @@ void Fl_Unix_System_Driver::remove_fd(int n, int events) { pollfds[j].events = e; } # else - if (fd[i].fd == n) { - int e = fd[i].events & ~events; + if (Fl_Unix_Screen_Driver::fd[i].fd == n) { + int e = Fl_Unix_Screen_Driver::fd[i].events & ~events; if (!e) continue; // if no events left, delete this fd - fd[i].events = e; + Fl_Unix_Screen_Driver::fd[i].events = e; } - if (fd[i].fd > maxfd) maxfd = fd[i].fd; + if (Fl_Unix_Screen_Driver::fd[i].fd > Fl_Unix_Screen_Driver::maxfd) Fl_Unix_Screen_Driver::maxfd = Fl_Unix_Screen_Driver::fd[i].fd; # endif // move it down in the array if necessary: if (j<i) { - fd[j] = fd[i]; + Fl_Unix_Screen_Driver::fd[j] = Fl_Unix_Screen_Driver::fd[i]; # if USE_POLL pollfds[j] = pollfds[i]; # endif } j++; } - nfds = j; + Fl_Unix_Screen_Driver::nfds = j; # if !USE_POLL - if (events & POLLIN) FD_CLR(n, &fdsets[0]); - if (events & POLLOUT) FD_CLR(n, &fdsets[1]); - if (events & POLLERR) FD_CLR(n, &fdsets[2]); + if (events & POLLIN) FD_CLR(n, &Fl_Unix_Screen_Driver::fdsets[0]); + if (events & POLLOUT) FD_CLR(n, &Fl_Unix_Screen_Driver::fdsets[1]); + if (events & POLLERR) FD_CLR(n, &Fl_Unix_Screen_Driver::fdsets[2]); # endif } @@ -762,85 +730,13 @@ void Fl_Unix_System_Driver::remove_fd(int n) { } -// these pointers are set by the Fl::lock() function: -static void nothing() {} -void (*fl_lock_function)() = nothing; -void (*fl_unlock_function)() = nothing; - - -// This is never called with time_to_wait < 0.0: -// It should return negative on error, 0 if nothing happens before -// timeout, and >0 if any callbacks were done. -int Fl_Unix_System_Driver::poll_or_select_with_delay(double time_to_wait) { -# if !USE_POLL - fd_set fdt[3]; - fdt[0] = fdsets[0]; - fdt[1] = fdsets[1]; - fdt[2] = fdsets[2]; -# endif - int n; - - fl_unlock_function(); - - if (time_to_wait < 2147483.648) { -# if USE_POLL - n = ::poll(pollfds, nfds, int(time_to_wait*1000 + .5)); -# else - timeval t; - t.tv_sec = int(time_to_wait); - t.tv_usec = int(1000000 * (time_to_wait-t.tv_sec)); - n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); -# endif - } else { -# if USE_POLL - n = ::poll(pollfds, nfds, -1); -# else - n = ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],0); -# endif - } - - fl_lock_function(); - - if (n > 0) { - for (int i=0; i<nfds; i++) { -# if USE_POLL - if (pollfds[i].revents) fd[i].cb(pollfds[i].fd, fd[i].arg); -# else - int f = fd[i].fd; - short revents = 0; - if (FD_ISSET(f,&fdt[0])) revents |= POLLIN; - if (FD_ISSET(f,&fdt[1])) revents |= POLLOUT; - if (FD_ISSET(f,&fdt[2])) revents |= POLLERR; - if (fd[i].events & revents) fd[i].cb(f, fd[i].arg); -# endif - } - } - return n; -} - -int Fl_Unix_System_Driver::poll_or_select() { - if (!nfds) return 0; // nothing to select or poll -# if USE_POLL - return ::poll(pollfds, nfds, 0); -# else - timeval t; - t.tv_sec = 0; - t.tv_usec = 0; - fd_set fdt[3]; - fdt[0] = fdsets[0]; - fdt[1] = fdsets[1]; - fdt[2] = fdsets[2]; - return ::select(maxfd+1,&fdt[0],&fdt[1],&fdt[2],&t); -# endif -} - - double Fl_Unix_System_Driver::wait(double time_to_wait) { + Fl_Unix_Screen_Driver *scr_dr = (Fl_Unix_Screen_Driver*)Fl::screen_driver(); time_to_wait = Fl_System_Driver::wait(time_to_wait); if (time_to_wait <= 0.0) { // do flush second so that the results of events are visible: - int ret = this->poll_or_select_with_delay(0.0); + int ret = scr_dr->poll_or_select_with_delay(0.0); Fl::flush(); return ret; } else { @@ -852,15 +748,16 @@ double Fl_Unix_System_Driver::wait(double time_to_wait) Fl_Timeout::elapse_timeouts(); time_to_wait = Fl_Timeout::time_to_wait(time_to_wait); } - return this->poll_or_select_with_delay(time_to_wait); + return scr_dr->poll_or_select_with_delay(time_to_wait); } } int Fl_Unix_System_Driver::ready() { + Fl_Unix_Screen_Driver *scr_dr = (Fl_Unix_Screen_Driver*)Fl::screen_driver(); Fl_Timeout::elapse_timeouts(); if (Fl_Timeout::time_to_wait(1.0) <= 0.0) return 1; - return this->poll_or_select(); + return scr_dr->poll_or_select(); } @@ -954,8 +851,3 @@ Fl_RGB_Image *Fl_Unix_System_Driver::own_bmp_to_RGB(char *bmp) { img->alloc_array = 1; return img; } - - -void *Fl_Unix_System_Driver::control_maximize_button(void *data) { - return NULL; -} diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H index aebc651ff..95c50fa0e 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H @@ -23,7 +23,7 @@ #ifndef FL_WAYLAND_SCREEN_DRIVER_H #define FL_WAYLAND_SCREEN_DRIVER_H -#include "../../Fl_Screen_Driver.H" +#include "../Unix/Fl_Unix_Screen_Driver.H" #include <wayland-client.h> class Fl_Window; @@ -54,7 +54,7 @@ struct seat { struct zwp_text_input_v3 *text_input; }; -class Fl_Wayland_Screen_Driver : public Fl_Screen_Driver +class Fl_Wayland_Screen_Driver : public Fl_Unix_Screen_Driver { friend class Fl_Screen_Driver; friend class Fl_Wayland_Graphics_Driver; @@ -176,6 +176,9 @@ public: static compositor_name compositor; // identifies the used Wayland compositor void set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win); void reset_spot(); + virtual void *control_maximize_button(void *data); + int event_key(int k); + int get_key(int k); }; diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx index 0ea7bad37..d0198c646 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx @@ -17,10 +17,7 @@ #include <config.h> #include "Fl_Wayland_Screen_Driver.H" #include "Fl_Wayland_Window_Driver.H" -#include "Fl_Wayland_System_Driver.H" -#if FLTK_USE_X11 -# include "../X11/Fl_X11_System_Driver.H" -#endif +#include "../Unix/Fl_Unix_System_Driver.H" #include "Fl_Wayland_Graphics_Driver.H" #include <wayland-cursor.h> #include "../../../libdecor/src/libdecor.h" @@ -1086,7 +1083,7 @@ static void fd_callback(int fd, struct wl_display *display) { } -Fl_Wayland_Screen_Driver::Fl_Wayland_Screen_Driver() : Fl_Screen_Driver() { +Fl_Wayland_Screen_Driver::Fl_Wayland_Screen_Driver() : Fl_Unix_Screen_Driver() { libdecor_context = NULL; seat = NULL; text_input_base = NULL; @@ -1478,6 +1475,73 @@ void Fl_Wayland_Screen_Driver::display(const char *d) } +void *Fl_Wayland_Screen_Driver::control_maximize_button(void *data) { + // The code below aims at removing the calling window's fullscreen button + // while dialog runs. Unfortunately, it doesn't work with some X11 window managers + // (e.g., KDE, xfce) because the button goes away but doesn't come back, + // so we move this code to a virtual member function. + // Noticeably, this code works OK under Wayland. + struct win_dims { + Fl_Widget_Tracker *tracker; + int minw, minh, maxw, maxh; + struct win_dims *next; + }; + + if (!data) { // this call turns each decorated window's maximize button off + struct win_dims *first_dim = NULL; + // consider all bordered, top-level FLTK windows + Fl_Window *win = Fl::first_window(); + while (win) { + if (!win->parent() && win->border() && + !( ((struct wld_window*)Fl_X::i(win)->xid)->state & LIBDECOR_WINDOW_STATE_MAXIMIZED) ) { + win_dims *dim = new win_dims; + dim->tracker = new Fl_Widget_Tracker(win); + Fl_Window_Driver *dr = Fl_Window_Driver::driver(win); + dim->minw = dr->minw(); + dim->minh = dr->minh(); + dim->maxw = dr->maxw(); + dim->maxh = dr->maxh(); + //make win un-resizable + win->size_range(win->w(), win->h(), win->w(), win->h()); + dim->next = first_dim; + first_dim = dim; + } + win = Fl::next_window(win); + } + return first_dim; + } else { // this call returns each decorated window's maximize button to its previous state + win_dims *first_dim = (win_dims *)data; + while (first_dim) { + win_dims *dim = first_dim; + //give back win its resizing parameters + if (dim->tracker->exists()) { + Fl_Window *win = (Fl_Window*)dim->tracker->widget(); + win->size_range(dim->minw, dim->minh, dim->maxw, dim->maxh); + } + first_dim = dim->next; + delete dim->tracker; + delete dim; + } + return NULL; + } +} + + +int Fl_Wayland_Screen_Driver::event_key(int k) { + if (k > FL_Button && k <= FL_Button+8) + return Fl::event_state(8<<(k-FL_Button)); + int sym = Fl::event_key(); + if (sym >= 'a' && sym <= 'z' ) sym -= 32; + if (k >= 'a' && k <= 'z' ) k -= 32; + return (Fl::event() == FL_KEYDOWN || Fl::event() == FL_SHORTCUT) && sym == k; +} + + +int Fl_Wayland_Screen_Driver::get_key(int k) { + return event_key(k); +} + + struct wl_display *fl_wl_display() { if (!Fl_Wayland_Screen_Driver::wl_display || !Fl_Wayland_Screen_Driver::wl_registry) return NULL; return Fl_Wayland_Screen_Driver::wl_display; diff --git a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx index 3b1e7bbf8..98ee9dcfe 100644 --- a/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Window_Driver.cxx @@ -19,7 +19,7 @@ #include "Fl_Wayland_Window_Driver.H" #include "Fl_Wayland_Screen_Driver.H" #include "Fl_Wayland_Graphics_Driver.H" -#include "Fl_Wayland_System_Driver.H" +#include "../Unix/Fl_Unix_System_Driver.H" #include <wayland-cursor.h> #include "../../../libdecor/src/libdecor.h" #include "xdg-shell-client-protocol.h" diff --git a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx index 38b7a1bb7..12ec62c51 100644 --- a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx +++ b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx @@ -27,7 +27,7 @@ # include "../../flstring.h" # include "Fl_Wayland_Screen_Driver.H" # include "Fl_Wayland_Window_Driver.H" -# include "Fl_Wayland_System_Driver.H" +# include "../Unix/Fl_Unix_System_Driver.H" # include "Fl_Wayland_Graphics_Driver.H" # include <errno.h> diff --git a/src/drivers/Wayland/fl_wayland_platform_init.cxx b/src/drivers/Wayland/fl_wayland_platform_init.cxx index 88b863b20..01d49ccb5 100644 --- a/src/drivers/Wayland/fl_wayland_platform_init.cxx +++ b/src/drivers/Wayland/fl_wayland_platform_init.cxx @@ -14,11 +14,11 @@ // https://www.fltk.org/bugs.php // - +#include <config.h> #include "Fl_Wayland_Copy_Surface_Driver.H" #include "Fl_Wayland_Graphics_Driver.H" #include "Fl_Wayland_Screen_Driver.H" -#include "Fl_Wayland_System_Driver.H" +#include "../Unix/Fl_Unix_System_Driver.H" #include "Fl_Wayland_Window_Driver.H" #include "Fl_Wayland_Image_Surface_Driver.H" #if FLTK_USE_X11 @@ -26,7 +26,6 @@ # include <cairo-xlib.h> # include "../Cairo/Fl_Display_Cairo_Graphics_Driver.H" # include "../X11/Fl_X11_Screen_Driver.H" -# include "../X11/Fl_X11_System_Driver.H" # include "../X11/Fl_X11_Window_Driver.H" # include "../Xlib/Fl_Xlib_Image_Surface_Driver.H" #endif @@ -114,10 +113,7 @@ static bool attempt_wayland() { Fl_System_Driver *Fl_System_Driver::newSystemDriver() { -#if FLTK_USE_X11 - if (!attempt_wayland()) return new Fl_X11_System_Driver(); -#endif - return new Fl_Wayland_System_Driver(); + return new Fl_Unix_System_Driver(); } diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index e48d7fb29..899b2cf3f 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -94,6 +94,9 @@ public: virtual void clipboard_notify_change(); // this one is implemented in Fl_win32.cxx void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); + // these two are implemented in Fl_get_key_win32.cxx + virtual int event_key(int); + virtual int get_key(int); }; diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H index 9855ba509..730d9320d 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H @@ -69,9 +69,6 @@ public: virtual int clocale_vprintf(FILE *output, const char *format, va_list args); virtual int clocale_vsnprintf(char *output, size_t output_size, const char *format, va_list args); virtual int clocale_vsscanf(const char *input, const char *format, va_list args); - // these 2 are in Fl_get_key_win32.cxx - virtual int event_key(int k); - virtual int get_key(int k); virtual int filename_list(const char *d, dirent ***list, int (*sort)(struct dirent **, struct dirent **), char *errmsg=NULL, int errmsg_sz=0); diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 71fcd0d77..5ff64ccad 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -24,14 +24,14 @@ #define FL_X11_SCREEN_DRIVER_H #include <config.h> -#include "../../Fl_Screen_Driver.H" +#include "../Unix/Fl_Unix_Screen_Driver.H" #include <X11/Xlib.h> class Fl_Window; -class Fl_X11_Screen_Driver : public Fl_Screen_Driver +class Fl_X11_Screen_Driver : public Fl_Unix_Screen_Driver { friend class Fl_Screen_Driver; protected: @@ -58,10 +58,21 @@ public: int screen_num_unscaled(int x, int y); #endif + Fl_X11_Screen_Driver(); static int ewmh_supported(); static void copy_image(const unsigned char* data, int W, int H, int destination); // --- display management virtual void display(const char *disp); + virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*); + virtual int poll_or_select_with_delay(double time_to_wait); + virtual int poll_or_select(); + virtual void own_colormap(); + virtual const char *shortcut_add_key_name(unsigned key, char *p, char *buf, const char **); + virtual int need_menu_handle_part1_extra() {return 1;} + virtual int need_menu_handle_part2() {return 1;} + // these 2 are in Fl_get_key.cxx + virtual int event_key(int); + virtual int get_key(int); virtual int visual(int flags); // --- screen configuration void init_workarea(); diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index 87a91636c..6876c6d47 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -18,7 +18,6 @@ #include <config.h> #include "Fl_X11_Screen_Driver.H" #include "Fl_X11_Window_Driver.H" -#include "Fl_X11_System_Driver.H" #include "../Posix/Fl_Posix_System_Driver.H" #include <FL/Fl.H> #include <FL/platform.H> @@ -69,6 +68,11 @@ char Fl_X11_Screen_Driver::fl_is_over_the_spot = 0; Window Fl_X11_Screen_Driver::xim_win = 0; +Fl_X11_Screen_Driver::Fl_X11_Screen_Driver() : Fl_Unix_Screen_Driver() { + // X11 screen driver does not use a key table + key_table = NULL; + key_table_size = 0; +} void Fl_X11_Screen_Driver::display(const char *d) { @@ -76,6 +80,60 @@ void Fl_X11_Screen_Driver::display(const char *d) } +int Fl_X11_Screen_Driver::XParseGeometry(const char* string, int* x, int* y, + unsigned int* width, unsigned int* height) { + return ::XParseGeometry(string, x, y, width, height); +} + + +void Fl_X11_Screen_Driver::own_colormap() { + fl_open_display(); +#if USE_COLORMAP + switch (fl_visual->c_class) { + case GrayScale : + case PseudoColor : + case DirectColor : + break; + default: + return; // don't do anything for non-colormapped visuals + } + int i; + XColor colors[16]; + // Get the first 16 colors from the default colormap... + for (i = 0; i < 16; i ++) colors[i].pixel = i; + XQueryColors(fl_display, fl_colormap, colors, 16); + // Create a new colormap... + fl_colormap = XCreateColormap(fl_display, + RootWindow(fl_display,fl_screen), + fl_visual->visual, AllocNone); + // Copy those first 16 colors to our own colormap: + for (i = 0; i < 16; i ++) + XAllocColor(fl_display, fl_colormap, colors + i); +#endif // USE_COLORMAP +} + + +const char *Fl_X11_Screen_Driver::shortcut_add_key_name(unsigned key, char *p, char *buf, const char **eom) +{ + const char* q; + if (key == FL_Enter || key == '\r') q = "Enter"; // don't use Xlib's "Return": + else if (key > 32 && key < 0x100) q = 0; + else q = XKeysymToString(key); + if (!q) { + p += fl_utf8encode(fl_toupper(key), p); + *p = 0; + return buf; + } + if (p > buf) { + strcpy(p,q); + return buf; + } else { + if (eom) *eom = q; + return q; + } +} + + static int test_visual(XVisualInfo& v, int flags) { if (v.screen != fl_screen) return 0; #if USE_COLORMAP diff --git a/src/drivers/X11/fl_X11_platform_init.cxx b/src/drivers/X11/fl_X11_platform_init.cxx index b26dfa444..1388beefd 100644 --- a/src/drivers/X11/fl_X11_platform_init.cxx +++ b/src/drivers/X11/fl_X11_platform_init.cxx @@ -23,7 +23,7 @@ # include "../Xlib/Fl_Xlib_Graphics_Driver.H" #endif #include "Fl_X11_Screen_Driver.H" -#include "Fl_X11_System_Driver.H" +#include "../Unix/Fl_Unix_System_Driver.H" #include "Fl_X11_Window_Driver.H" #include "../Xlib/Fl_Xlib_Image_Surface_Driver.H" #include "../Xlib/Fl_Font.H" @@ -155,7 +155,7 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver() Fl_System_Driver *Fl_System_Driver::newSystemDriver() { - return new Fl_X11_System_Driver(); + return new Fl_Unix_System_Driver(); } |
