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/X11 | |
| parent | b663e272e7f39063a5c1bf744038ded0a7566990 (diff) | |
Create class Fl_Unix_Screen_Driver used by X11 and Wayland platforms
Diffstat (limited to 'src/drivers/X11')
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.H | 15 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 60 | ||||
| -rw-r--r-- | src/drivers/X11/fl_X11_platform_init.cxx | 4 |
3 files changed, 74 insertions, 5 deletions
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(); } |
