diff options
Diffstat (limited to 'src/drivers/X11')
| -rw-r--r-- | src/drivers/X11/Fl_X11_Gl_Window_Driver.cxx | 18 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 4 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Window_Driver.H | 8 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Window_Driver.cxx | 71 | ||||
| -rw-r--r-- | src/drivers/X11/fl_X11_platform_init.cxx | 11 |
5 files changed, 93 insertions, 19 deletions
diff --git a/src/drivers/X11/Fl_X11_Gl_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Gl_Window_Driver.cxx index 9a092756a..b85aadd39 100644 --- a/src/drivers/X11/Fl_X11_Gl_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Gl_Window_Driver.cxx @@ -1,7 +1,7 @@ // // Class Fl_X11_Gl_Window_Driver for the Fast Light Tool Kit (FLTK). // -// Copyright 2021 by Bill Spitzak and others. +// 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 @@ -21,8 +21,6 @@ #include "../../Fl_Screen_Driver.H" #include "../../Fl_Window_Driver.H" #include "Fl_X11_Gl_Window_Driver.H" -#include "../Xlib/Fl_Font.H" -#include "../Xlib/Fl_Xlib_Graphics_Driver.H" # include <GL/glx.h> # if ! defined(GLX_VERSION_1_3) # typedef void *GLXFBConfig; @@ -61,7 +59,7 @@ void Fl_X11_Gl_Window_Driver::gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize) { * is not working on this platform. This code might not reliably render glyphs * from higher codepoints. */ if (!fl_fontsize->listbase) { -#if USE_XFT +#if USE_XFT && !FLTK_USE_CAIRO /* Ideally, for XFT, we need a glXUseXftFont implementation here... But we * do not have such a thing. Instead, we try to find a legacy Xlib font that * matches the current XFT font and use that. @@ -288,7 +286,7 @@ GLContext Fl_X11_Gl_Window_Driver::create_gl_context(Fl_Window* window, const Fl XSetErrorHandler(oldHandler); } if (!ctx) { // use OpenGL 1-style context creation - ctx = glXCreateContext(fl_display, ((Fl_X11_Gl_Choice*)g)->vis, shared_ctx, true); + ctx = glXCreateContext(fl_display, ((Fl_X11_Gl_Choice*)g)->vis, (GLXContext)shared_ctx, true); } if (ctx) add_context(ctx); @@ -299,7 +297,7 @@ GLContext Fl_X11_Gl_Window_Driver::create_gl_context(Fl_Window* window, const Fl GLContext Fl_X11_Gl_Window_Driver::create_gl_context(XVisualInfo *vis) { GLContext shared_ctx = 0; if (context_list && nContext) shared_ctx = context_list[0]; - GLContext context = glXCreateContext(fl_display, vis, shared_ctx, 1); + GLContext context = glXCreateContext(fl_display, vis, (GLXContext)shared_ctx, 1); if (context) add_context(context); return context; @@ -309,7 +307,7 @@ void Fl_X11_Gl_Window_Driver::set_gl_context(Fl_Window* w, GLContext context) { if (context != cached_context || w != cached_window) { cached_context = context; cached_window = w; - glXMakeCurrent(fl_display, fl_xid(w), context); + glXMakeCurrent(fl_display, fl_xid(w), (GLXContext)context); } } @@ -319,7 +317,7 @@ void Fl_X11_Gl_Window_Driver::delete_gl_context(GLContext context) { cached_window = 0; glXMakeCurrent(fl_display, 0, 0); } - glXDestroyContext(fl_display, context); + glXDestroyContext(fl_display, (GLXContext)context); del_context(context); } @@ -394,4 +392,8 @@ void Fl_X11_Gl_Window_Driver::gl_start() { glXWaitX(); } + +FL_EXPORT GLXContext fl_x11_glcontext(GLContext rc) { return (GLXContext)rc; } + + #endif // HAVE_GL diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index b8fdd20c1..87a91636c 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -17,11 +17,9 @@ #include <config.h> #include "Fl_X11_Screen_Driver.H" -#include "../Xlib/Fl_Font.H" #include "Fl_X11_Window_Driver.H" #include "Fl_X11_System_Driver.H" #include "../Posix/Fl_Posix_System_Driver.H" -#include "../Xlib/Fl_Xlib_Graphics_Driver.H" #include <FL/Fl.H> #include <FL/platform.H> #include <FL/fl_ask.H> @@ -986,7 +984,7 @@ void Fl_X11_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &hei int px, py; unsigned w, h, b, d; Window root; - XGetGeometry(fl_display, off, &root, &px, &py, &w, &h, &b, &d); + XGetGeometry(fl_display, (Pixmap)off, &root, &px, &py, &w, &h, &b, &d); width = (int)w; height = (int)h; } diff --git a/src/drivers/X11/Fl_X11_Window_Driver.H b/src/drivers/X11/Fl_X11_Window_Driver.H index 84b11ad16..13c1cf900 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.H +++ b/src/drivers/X11/Fl_X11_Window_Driver.H @@ -26,6 +26,11 @@ #include "../../Fl_Window_Driver.H" #include <config.h> #include <FL/platform.H> // for Cursor + +#if FLTK_USE_CAIRO +typedef struct _cairo cairo_t; +#endif // FLTK_USE_CAIRO + class Fl_Bitmap; /* @@ -71,6 +76,9 @@ private: int screen_num_; void screen_num(int n) { screen_num_ = n; } #endif // USE_XFT +#if FLTK_USE_CAIRO + cairo_t *cairo_; +#endif // FLTK_USE_CAIRO void decorated_win_size(int &w, int &h); void combine_mask(); void shape_bitmap_(Fl_Image* b); diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index ed9dd8fcb..a5302904f 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -18,9 +18,13 @@ #include <config.h> #include "Fl_X11_Window_Driver.H" #include "Fl_X11_Screen_Driver.H" -#include "../Xlib/Fl_Xlib_Graphics_Driver.H" +#if FLTK_USE_CAIRO +# include <cairo-xlib.h> +# include "../Cairo/Fl_Display_Cairo_Graphics_Driver.H" +#else +# include "../Xlib/Fl_Xlib_Graphics_Driver.H" +#endif // FLTK_USE_CAIRO -#include "../../Fl_Screen_Driver.H" #include <FL/Fl_Overlay_Window.H> #include <FL/Fl_Menu_Window.H> #include <FL/Fl_Tooltip.H> @@ -53,6 +57,9 @@ Fl_X11_Window_Driver::Fl_X11_Window_Driver(Fl_Window *win) #if USE_XFT screen_num_ = -1; #endif +#if FLTK_USE_CAIRO + cairo_ = NULL; +#endif } @@ -151,9 +158,17 @@ void Fl_X11_Window_Driver::flush_double(int erase_overlay) pWindow->make_current(); // make sure fl_gc is non-zero Fl_X *i = Fl_X::i(pWindow); if (!other_xid) { - other_xid = fl_create_offscreen(w(), h()); + other_xid = fl_create_offscreen(w(), h()); +#if FLTK_USE_CAIRO + fl_begin_offscreen(other_xid); + cairo_ = ((Fl_Cairo_Graphics_Driver*)fl_graphics_driver)->cr(); + fl_end_offscreen(); +#endif pWindow->clear_damage(FL_DAMAGE_ALL); } +#if FLTK_USE_CAIRO + ((Fl_Display_Cairo_Graphics_Driver*)fl_graphics_driver)->set_cairo(cairo_); +#endif if (pWindow->damage() & ~FL_DAMAGE_EXPOSE) { fl_clip_region(i->region); i->region = 0; fl_window = other_xid; @@ -176,8 +191,21 @@ void Fl_X11_Window_Driver::flush_overlay() int erase_overlay = (pWindow->damage()&FL_DAMAGE_OVERLAY) | (overlay() == pWindow); pWindow->clear_damage((uchar)(pWindow->damage()&~FL_DAMAGE_OVERLAY)); flush_double(erase_overlay); - Fl_Overlay_Window *oWindow = pWindow->as_overlay_window(); - if (overlay() == oWindow) oWindow->draw_overlay(); + if (overlay() == pWindow) { +#if FLTK_USE_CAIRO + float scale = fl_graphics_driver->scale(); + int W = pWindow->w() * scale, H = pWindow->h() * scale; + cairo_surface_t *s = cairo_xlib_surface_create(fl_display, Fl_X::i(pWindow)->xid, fl_visual->visual, W, H); + cairo_t *overlay_cairo = cairo_create(s); + cairo_surface_destroy(s); + cairo_save(overlay_cairo); + ((Fl_Display_Cairo_Graphics_Driver*)fl_graphics_driver)->set_cairo(overlay_cairo); +#endif + pWindow->as_overlay_window()->draw_overlay(); +#if FLTK_USE_CAIRO + cairo_destroy(overlay_cairo); +#endif + } } @@ -373,7 +401,21 @@ void Fl_X11_Window_Driver::make_current() { } fl_window = fl_xid(pWindow); fl_graphics_driver->clip_region(0); -#if USE_XFT + +#if FLTK_USE_CAIRO + float scale = Fl::screen_scale(screen_num()); // get the screen scaling factor + if (!pWindow->as_double_window()) { + if (!cairo_) { + int W = pWindow->w() * scale, H = pWindow->h() * scale; + cairo_surface_t *s = cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H); + cairo_ = cairo_create(s); + cairo_surface_destroy(s); + cairo_save(cairo_); + } + ((Fl_Display_Cairo_Graphics_Driver*)fl_graphics_driver)->set_cairo(cairo_); + } + fl_graphics_driver->scale(scale); +#elif USE_XFT ((Fl_Xlib_Graphics_Driver*)fl_graphics_driver)->scale(Fl::screen_driver()->scale(screen_num())); #endif @@ -388,10 +430,16 @@ void Fl_X11_Window_Driver::hide() { Fl_X* ip = Fl_X::i(pWindow); if (hide_common()) return; if (ip->region) Fl_Graphics_Driver::default_driver().XDestroyRegion(ip->region); -# if USE_XFT +# if USE_XFT && ! FLTK_USE_CAIRO Fl_Xlib_Graphics_Driver::destroy_xft_draw(ip->xid); screen_num_ = -1; # endif +# if FLTK_USE_CAIRO + if (cairo_ && !pWindow->as_double_window()) { + cairo_destroy(cairo_); + cairo_ = NULL; + } +# endif // this test makes sure ip->xid has not been destroyed already if (ip->xid) XDestroyWindow(fl_display, ip->xid); delete ip; @@ -504,6 +552,15 @@ const Fl_Image* Fl_X11_Window_Driver::shape() { return shape_data_ ? shape_data_->shape_ : NULL; } +Fl_Window *fl_x11_find(Window xid) { + return Fl_Window_Driver::find((fl_uintptr_t)xid); +} + +Window fl_x11_xid(const Fl_Window *win) { + return (Window)Fl_Window_Driver::xid(win); +} + + #if USE_XFT Fl_X11_Window_Driver::type_for_resize_window_between_screens Fl_X11_Window_Driver::data_for_resize_window_between_screens_ = {0, false}; diff --git a/src/drivers/X11/fl_X11_platform_init.cxx b/src/drivers/X11/fl_X11_platform_init.cxx index 3bcf21370..b26dfa444 100644 --- a/src/drivers/X11/fl_X11_platform_init.cxx +++ b/src/drivers/X11/fl_X11_platform_init.cxx @@ -14,9 +14,14 @@ // https://www.fltk.org/bugs.php // +#include <config.h> #include <FL/platform.H> #include "../Xlib/Fl_Xlib_Copy_Surface_Driver.H" -#include "../Xlib/Fl_Xlib_Graphics_Driver.H" +#if FLTK_USE_CAIRO +# include "../Cairo/Fl_Display_Cairo_Graphics_Driver.H" +#else +# include "../Xlib/Fl_Xlib_Graphics_Driver.H" +#endif #include "Fl_X11_Screen_Driver.H" #include "Fl_X11_System_Driver.H" #include "Fl_X11_Window_Driver.H" @@ -127,7 +132,11 @@ FL_EXPORT Fl_Fontdesc* fl_fonts = (Fl_Fontdesc*)built_in_table; Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver() { +#if FLTK_USE_CAIRO + return new Fl_Display_Cairo_Graphics_Driver(); +#else return new Fl_Xlib_Graphics_Driver(); +#endif } |
