FLTK 1.3.11
x.H
1 //
2 // X11 header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2024 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // http://www.fltk.org/COPYING.php
11 //
12 // Please report all bugs and problems on the following page:
13 //
14 // http://www.fltk.org/str.php
15 //
16 
17 // These are internal fltk symbols that are necessary or useful for
18 // calling Xlib. You should include this file if (and ONLY if) you
19 // need to call Xlib directly. These symbols may not exist on non-X
20 // systems.
21 
22 #if !defined(Fl_X_H) && !defined(FL_DOXYGEN)
23 # define Fl_X_H
24 
25 # include "Enumerations.H"
26 
27 # ifdef WIN32
28 # include "win32.H"
29 # elif defined(__APPLE__)
30 # include "mac.H"
31 # else
32 # if defined(_ABIN32) || defined(_ABI64) // fix for broken SGI Irix X .h files
33 # pragma set woff 3322
34 # endif
35 # include <X11/Xlib.h>
36 # include <X11/Xutil.h>
37 # if defined(_ABIN32) || defined(_ABI64)
38 # pragma reset woff 3322
39 # endif
40 # include <X11/Xatom.h>
41 # include "Fl_Window.H"
42 // Mirror X definition of Region to Fl_Region, for portability...
43 typedef Region Fl_Region;
44 
45 FL_EXPORT void fl_open_display();
46 FL_EXPORT void fl_open_display(Display*);
47 FL_EXPORT void fl_close_display();
48 
49 // constant info about the X server connection:
50 extern FL_EXPORT Display *fl_display;
51 extern FL_EXPORT int fl_screen;
52 extern FL_EXPORT XVisualInfo *fl_visual;
53 extern FL_EXPORT Colormap fl_colormap;
54 
55 
56 // drawing functions:
57 extern FL_EXPORT GC fl_gc;
58 extern FL_EXPORT Window fl_window;
59 FL_EXPORT ulong fl_xpixel(Fl_Color i);
60 FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);
61 FL_EXPORT void fl_clip_region(Fl_Region);
62 FL_EXPORT Fl_Region fl_clip_region();
63 
64 // feed events into fltk:
65 FL_EXPORT int fl_handle(const XEvent&);
66 
67 // you can use these in Fl::add_handler() to look at events:
68 extern FL_EXPORT const XEvent* fl_xevent;
69 extern FL_EXPORT ulong fl_event_time;
70 
71 // off-screen pixmaps: create, destroy, draw into, copy to window:
72 typedef ulong Fl_Offscreen;
73 # define fl_create_offscreen(w,h) XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, fl_visual->depth)
74 # define fl_create_offscreen_with_alpha(w,h) XCreatePixmap(fl_display, RootWindow(fl_display, fl_screen), w, h, 32)
75 // begin/end are macros that save the old state in local variables:
76 # define fl_begin_offscreen(pixmap) \
77  Window _sw=fl_window; fl_window=pixmap; \
78  GC _sgc = fl_gc; if (!_sgc) fl_gc = XCreateGC(fl_display, pixmap, 0, 0); \
79  Fl_Surface_Device *_ss = Fl_Surface_Device::surface(); Fl_Display_Device::display_device()->set_current(); \
80  fl_push_no_clip()
81 # define fl_end_offscreen() \
82  fl_pop_clip(); fl_window = _sw; _ss->set_current(); \
83  if (!_sgc) XFreeGC(fl_display, fl_gc); \
84  fl_gc = _sgc
85 
86 extern FL_EXPORT void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
87 # define fl_delete_offscreen(pixmap) XFreePixmap(fl_display, pixmap)
88 
89 // Bitmap masks
90 typedef ulong Fl_Bitmask;
91 
92 extern FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data);
93 extern FL_EXPORT Fl_Bitmask fl_create_alphamask(int w, int h, int d, int ld, const uchar *data);
94 extern FL_EXPORT void fl_delete_bitmask(Fl_Bitmask bm);
95 
96 #if defined(FL_LIBRARY) || defined(FL_INTERNALS)
97 extern FL_EXPORT Window fl_message_window;
98 extern FL_EXPORT void *fl_xftfont;
99 FL_EXPORT Fl_Region XRectangleRegion(int x, int y, int w, int h); // in fl_rect.cxx
100 
101 // access to core fonts:
102 // This class provides a "smart pointer" that returns a pointer to an XFontStruct.
103 // The global variable fl_xfont can be called wherever a bitmap "core" font is
104 // needed, e.g. when rendering to a GL context under X11.
105 // With Xlib / X11 fonts, fl_xfont will return the current selected font.
106 // With XFT / X11 fonts, fl_xfont will attempt to return the bitmap "core" font most
107 // similar to (usually the same as) the current XFT font.
108 class FL_EXPORT Fl_XFont_On_Demand
109 {
110 public:
111  Fl_XFont_On_Demand(XFontStruct* p = NULL) : ptr(p) { }
112  Fl_XFont_On_Demand& operator=(const Fl_XFont_On_Demand& x)
113  { ptr = x.ptr; return *this; }
114  Fl_XFont_On_Demand& operator=(XFontStruct* p)
115  { ptr = p; return *this; }
116  XFontStruct* value();
117  operator XFontStruct*() { return value(); }
118  XFontStruct& operator*() { return *value(); }
119  XFontStruct* operator->() { return value(); }
120  bool operator==(const Fl_XFont_On_Demand& x) { return ptr == x.ptr; }
121  bool operator!=(const Fl_XFont_On_Demand& x) { return ptr != x.ptr; }
122 private:
123  XFontStruct *ptr;
124 };
125 extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
126 extern FL_EXPORT XFontStruct* fl_X_core_font();
127 
128 // this object contains all X-specific stuff about a window:
129 // Warning: this object is highly subject to change!
130 // FL_LIBRARY or FL_INTERNALS must be defined to access this class.
131 class FL_EXPORT Fl_X {
132 public:
133  Window xid;
134  Window other_xid;
135  Fl_Window *w;
136  Fl_Region region;
137  Fl_X *next;
138  char wait_for_expose;
139  char backbuffer_bad; // used for XDBE
140  static Fl_X* first;
141  static Fl_X* i(const Fl_Window* wi) {return wi->i;}
142  void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
143  void sendxjunk();
144  static void set_default_icons(const Fl_RGB_Image*[], int);
145  void set_icons();
146  int set_cursor(Fl_Cursor);
147  int set_cursor(const Fl_RGB_Image*, int, int);
148  static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
149  static Fl_X* set_xid(Fl_Window*, Window);
150  // kludges to get around protection:
151  void flush() {w->flush();}
152  static void x(Fl_Window* wi, int X) {wi->x(X);}
153  static void y(Fl_Window* wi, int Y) {wi->y(Y);}
154  static int ewmh_supported();
155  static int xrender_supported();
156  static void activate_window(Window w);
157 };
158 
159 extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
160 extern FL_EXPORT int fl_background_pixel; // hack into Fl_X::make_xid()
161 
162 inline Window fl_xid(const Fl_Window* w) { Fl_X *xTemp = Fl_X::i(w); return xTemp ? xTemp->xid : 0; }
163 
164 #else
165 
166 extern FL_EXPORT Window fl_xid_(const Fl_Window* w);
167 #define fl_xid(w) fl_xid_(w)
168 
169 #endif // FL_LIBRARY || FL_INTERNALS
170 
171 FL_EXPORT Fl_Window* fl_find(Window xid);
172 
173 
174 // Dummy function to register a function for opening files via the window manager...
175 inline void fl_open_callback(void (*)(const char *)) {}
176 
177 extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
178 
179 # endif
180 #endif
This widget produces an actual window.
Definition: Fl_Window.H:57
Fl_Cursor
The following constants define the mouse cursors that are available in FLTK.
Definition: Enumerations.H:1055
void fl_clip_region(Fl_Region r)
Replaces the top of the clipping stack with a clipping region of any shape.
Definition: fl_draw.H:136
void y(int v)
Internal use only.
Definition: Fl_Widget.H:141
void fl_open_callback(void(*cb)(const char *))
Register a function called for each file dropped onto an application icon.
The Fl_RGB_Image class supports caching and drawing of full-color images with 1 to 4 channels of colo...
Definition: Fl_Image.H:202
unsigned long ulong
unsigned long
Definition: fl_types.h:32
This file contains type definitions and general enumerations.
Fl_Window widget .
ulong fl_xpixel(uchar r, uchar g, uchar b)
Returns the X pixel number used to draw the given rgb color.
Definition: fl_color.cxx:150
unsigned int Fl_Color
An FLTK color value; see also Colors.
Definition: Enumerations.H:941
virtual void flush()
Forces the window to be drawn, this window is also made current and calls draw(). ...
Definition: Fl.cxx:1945
void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy)
Copy a rectangular area of the given offscreen buffer into the current drawing destination.
Definition: Fl_Double_Window.cxx:94
Mac OS X-specific symbols.
unsigned char uchar
unsigned char
Definition: fl_types.h:30
void x(int v)
Internal use only.
Definition: Fl_Widget.H:139