libxputty 0.1
Loading...
Searching...
No Matches
Functions | Variables
xwidget-linux.c File Reference

Go to the source code of this file.

Functions

int intern_error_handler (Display *dpy, XErrorEvent *e)
 
char * utf8_from_locale (char *localestr)
 utf8_from_locale - convert active codepage to utf8 must be freed by the caller
 
char * locale_from_utf8 (char *utf8str)
 locale_from_utf8 - convert utf8 to active codepage must be freed by the caller
 
Displayos_open_display (char *display_name)
 os_open_display - Connect to the display to use
 
void os_close_display (Display *dpy)
 os_close_display - Close connection to the used display
 
void os_destroy_window (Widget_t *w)
 os_destroy_window - destroy a widget (close and remove from processing)
 
Window os_get_root_window (Xputty *main, int flag)
 os_get_root_window - get a pointer to the root window (desktop)
 
void os_translate_coords (Widget_t *w, Window from_window, Window to_window, int from_x, int from_y, int *to_x, int *to_y)
 os_translate_coords - get x,y related to destination Window
 
void os_get_window_metrics (Widget_t *w_, Metrics_t *metrics)
 os_get_window_metrics - Get the Merics_t struct related to a Widget_t
 
void os_set_window_min_size (Widget_t *w, int min_width, int min_height, int base_width, int base_height)
 os_set_window_min_size - Set the min and base size of a Widget_t
 
void os_move_window (Display *dpy, Widget_t *w, int x, int y)
 os_move_window - Move a Widget_t
 
void os_resize_window (Display *dpy, Widget_t *w, int x, int y)
 os_resize_window - Resize a Widget_t
 
void os_get_surface_size (cairo_surface_t *surface, int *width, int *height)
 os_get_surface_size - get the size of the cairo surface
 
void os_set_widget_surface_size (Widget_t *w, int width, int height)
 os_set_widget_surface_size - set the size of a Widget_t cairo surface
 
void os_create_main_window_and_surface (Widget_t *w, Xputty *app, Window win, int x, int y, int width, int height)
 os_create_main_window_and_surface - create a Widget_t with a acairo surface this function is used mainly internal on create_window()
 
void os_create_widget_window_and_surface (Widget_t *w, Xputty *app, Widget_t *parent, int x, int y, int width, int height)
 os_create_main_widget_and_surface - create a Widget_t with a acairo surface this function is used mainly internal on create_widget()
 
void os_set_title (Widget_t *w, const char *title)
 os_set_title - Set the title of a Widget_t
 
void os_widget_show (Widget_t *w)
 os_widget_show - Show a Widget_t
 
void os_widget_hide (Widget_t *w)
 os_widget_hide - Hide a Widget_t
 
void os_show_tooltip (Widget_t *wid, Widget_t *w)
 os_show_tooltip - Show a tooltip of a Widget_t
 
void os_expose_widget (Widget_t *w)
 os_expose_widget - Draw the the back buffer to the Widget_t surface
 
void os_widget_event_loop (void *w_, void *event, Xputty *main, void *user_data)
 os_widget_event_loop - the Widget_t event loop on windows all messges goes into WndProc, so stub here
 
void widget_set_dnd_aware (Widget_t *w)
 widget_set_dnd_aware - allow drag and drop for on Widget_t
 
void widget_set_dnd_unaware (Widget_t *w)
 widget_set_dnd_unaware - disable drag and drop for on Widget_t
 
void strremove (char *str, const char *sub)
 
void strdecode (char *target, const char *needle, const char *replacement)
 strdecode - replace string in char*
 
void handle_drag_data (Widget_t *w, XEvent *event)
 handle_drag_data - handle recived drag data
 
void handle_dnd_enter (Xputty *main, XEvent *event)
 handle_drag_enter - handle drag event enter the Widget_t
 
void send_dnd_status_event (Widget_t *w, XEvent *event)
 send_dnd_status_event - notify the drag sender that prepared to recive the event
 
void send_dnd_finished_event (Widget_t *w, XEvent *event)
 send_dnd_finished_event - notify the drag sender that the event is handled
 
int have_paste (Widget_t *w)
 have_paste - check if clipboard contain a textbuffer
 
void request_paste_from_clipboard (Widget_t *w)
 request_paste_from_clipboard - request textbuffer from clipboard
 
void receive_paste_from_clipboard (Widget_t *w, XEvent *event)
 receive_paste_from_clipboard - receive textbuffer from clipboard
 
void copy_to_clipboard (Widget_t *w, char *text, int size)
 copy_to_clipboard - send textbuffer to clipboard
 
void send_to_clipboard (Widget_t *w, XEvent *event)
 send_to_clipboard - send textbuffer to clipboard on request
 
void os_send_configure_event (Widget_t *w, int x, int y, int width, int height)
 os_send_configure_event - Send a configure event to a Widget_t
 
void os_send_button_press_event (Widget_t *w)
 os_send_button_press_event - Send a button press event to a Widget_t see XButtonEvent
 
void os_send_button_release_event (Widget_t *w)
 os_send_button_release_event - Send a button release event to a Widget_t see XButtonEvent
 
void os_send_systray_message (Widget_t *w)
 os_send_send_systray_message - Send a systray event to a Widget_t only working on Linux for now
 
void os_transparent_draw (void *w_, void *user_data)
 os_transparent_draw - Draw the Widget_t to the back buffer
 
void os_adjustment_callback (void *w_, void *user_data)
 os_adjustment_callback - called when a adjustment value have changed used internal for redraw the Widget_t
 
int os_grab_pointer (Widget_t *w)
 os_grab_pointer - grab the mouse pointer. Works only on linux
 
void os_set_input_mask (Widget_t *w)
 os_set_input_mask - set the Event mask to a Widget_t only work on linux, stub on Windows
 
void os_set_window_attrb (Widget_t *w)
 os_set_window_attrb - set the attribute mask to a Widget_t only work on linux, stub on Windows
 
void os_set_transient_for_hint (Widget_t *parent, Widget_t *w)
 os_set_ transient_for_hint - set a Widget_t transient to a other Widget_t only work on linux, stub on Windows
 
int os_get_screen_height (Widget_t *w)
 os_get_screen_height - Get the height of the used Display
 
int os_get_screen_width (Widget_t *w)
 os_get_screen_width - Get the width of the used Display
 
bool os_is_directory (const char *filename)
 os_is directory - check if a given path is a directory or a file
 
char * os_get_home_dir ()
 os_get_home_dir - get the users home directory
 
bool os_get_keyboard_input (Widget_t *w, XKeyEvent *key, char *buf, size_t bufsize)
 os_ get_keyboard_input - Get the Keyboard input and convert it to utf8
 
void os_free_pixmap (Widget_t *w, Pixmap pixmap)
 os_free_pixmap - Free the memory used by a Pixmap only Linux, stub otherwise
 
void os_quit (Widget_t *w)
 os_quit - quit the main loop and free all used memory
 
void os_quit_widget (Widget_t *w)
 os_quit_widget - remove a Widget_t from the main loop and free it's used memory
 
Atom os_register_wm_delete_window (Widget_t *wid)
 os_register_wm_delete_window - Get the needed Atom to send a widget delete message
 
Atom os_register_widget_destroy (Widget_t *wid)
 os_register_widget_destroy - Get the needed Atom to send a widget destroy message
 
void os_main_run (Xputty *main)
 os_main_run - start the event loop
 
void os_run_embedded (Xputty *main)
 os_run_embedded - the event handling when run embedded on windows all messges goes into WndProc, so stub here
 
void os_init_dnd (Xputty *main)
 os_init_dnd - register a Widget_t for handling drag and drop events only implemented on linux
 

Variables

int(* default_error_handler )(Display *dpy, XErrorEvent *e)
 

Function Documentation

◆ copy_to_clipboard()

void copy_to_clipboard ( Widget_t w,
char *  text,
int  size 
)

copy_to_clipboard - send textbuffer to clipboard

Parameters
w- the Widget_t to send the event
text- the text buffer to send to clipboard
size- the size of the buffer to send

Definition at line 586 of file xwidget-linux.c.

586 {
587 XSetSelectionOwner (w->app->dpy, w->app->selection, w->widget, 0);
588 if (XGetSelectionOwner (w->app->dpy, w->app->selection) != w->widget) return;
589 free(w->app->ctext);
590 w->app->ctext = NULL;
591 w->app->ctext = (unsigned char*)strndup(text, size);
592 w->app->csize = size;
593}
Window widget
Definition xwidget.h:469
Xputty * app
Definition xwidget.h:465
Display * dpy
Definition xputty.h:232
Atom selection
Definition xputty.h:278
int csize
Definition xputty.h:252
unsigned char * ctext
Definition xputty.h:244

References Widget_t::app, Xputty::csize, Xputty::ctext, Xputty::dpy, Xputty::selection, and Widget_t::widget.

◆ handle_dnd_enter()

void handle_dnd_enter ( Xputty main,
XEvent event 
)

handle_drag_enter - handle drag event enter the Widget_t

Parameters
main- pointer to the Xputty *main struct running
event- the drag event contain the drop data

Definition at line 481 of file xwidget-linux.c.

481 {
482 main->dnd_source_window = DND_SOURCE_WIN(event);
483 main->dnd_version = 0;
484 if (DND_STATUS_ACCEPT(event)) {
485 main->dnd_version = DND_VERSION(event);
486 if (main->dnd_version > 5) return;
487 Atom type = 0;
488 int format;
489 unsigned long count, remaining;
490 unsigned char *data = 0;
491
492 XGetWindowProperty (main->dpy, main->dnd_source_window, main->XdndTypeList,
493 0, 0x8000000L, False, XA_ATOM, &type, &format, &count, &remaining, &data);
494 if (!data || type != XA_ATOM || format != 32) {
495 if (data) {
496 XFree (data);
497 }
498 return;
499 }
500 Atom* types = (Atom*)data;
501 for (unsigned long l = 1; l < count; l++) {
502 if ((types[l] == main->dnd_type_uri) ||
503 (types[l] == main->dnd_type_text) ||
504 (types[l] == main->dnd_type_utf8)) {
505 main->dnd_type = types[l];
506 break;
507 }
508 }
509 if (data) {
510 XFree (data);
511 }
512 } else {
513 for (int i = 2; i < 5; ++i) {
514 if ((event->xclient.data.l[i] == main->dnd_type_uri) ||
515 (event->xclient.data.l[i] == main->dnd_type_text) ||
516 (event->xclient.data.l[i] == main->dnd_type_utf8)) {
517 main->dnd_type = event->xclient.data.l[i];
518 break;
519 }
520 }
521 }
522}
Window dnd_source_window
Definition xputty.h:261
Atom dnd_type_uri
Definition xputty.h:274
int dnd_version
Definition xputty.h:254
Atom dnd_type
Definition xputty.h:276
Atom XdndTypeList
Definition xputty.h:263
Atom dnd_type_utf8
Definition xputty.h:275
Atom dnd_type_text
Definition xputty.h:273
unsigned long int Atom

References Xputty::dnd_source_window, Xputty::dnd_type, Xputty::dnd_type_text, Xputty::dnd_type_uri, Xputty::dnd_type_utf8, Xputty::dnd_version, Xputty::dpy, and Xputty::XdndTypeList.

Referenced by os_widget_event_loop().

◆ handle_drag_data()

void handle_drag_data ( Widget_t w,
XEvent event 
)

handle_drag_data - handle recived drag data

Parameters
w- the Widget_t recive the event
event- the drag event contain the drop data

Definition at line 455 of file xwidget-linux.c.

455 {
456 if (event->xselection.property != w->app->XdndSelection) return;
457
458 Atom type;
459 int format;
460 unsigned long count = 0, remaining;
461 unsigned char* data = 0;
462
463 XGetWindowProperty(w->app->dpy,w->widget, event->xselection.property,
464 0, 65536, True, w->app->dnd_type, &type, &format,
465 &count, &remaining, &data);
466
467 send_dnd_finished_event (w, event);
468
469 if (!data || count == 0) {
470 return;
471 }
472 char* dndfile = (char*)data;
473 strdecode(dndfile, "%20", " ");
474 strremove(dndfile, "file://");
475 w->func.dnd_notify_callback(w, (void*)&dndfile);
476 w->app->dnd_type = None;
477 w->app->dnd_source_window = 0;
478 free(data);
479}
xevfunc dnd_notify_callback
Definition xwidget.h:97
Func_t func
Definition xwidget.h:481
Atom XdndSelection
Definition xputty.h:264
void strdecode(char *target, const char *needle, const char *replacement)
strdecode - replace string in char*
void send_dnd_finished_event(Widget_t *w, XEvent *event)
send_dnd_finished_event - notify the drag sender that the event is handled
void strremove(char *str, const char *sub)

References Widget_t::app, Func_t::dnd_notify_callback, Xputty::dnd_source_window, Xputty::dnd_type, Xputty::dpy, Widget_t::func, send_dnd_finished_event(), strdecode(), strremove(), Widget_t::widget, and Xputty::XdndSelection.

Referenced by os_widget_event_loop().

◆ have_paste()

int have_paste ( Widget_t w)

have_paste - check if clipboard contain a textbuffer

Parameters
w- the Widget_t to send the request

Definition at line 557 of file xwidget-linux.c.

557 {
558 return XGetSelectionOwner(w->app->dpy,w->app->selection);
559}

References Widget_t::app, Xputty::dpy, and Xputty::selection.

◆ intern_error_handler()

int intern_error_handler ( Display dpy,
XErrorEvent *  e 
)

Definition at line 36 of file xwidget-linux.c.

36 {
37 return 0;
38}

Referenced by os_send_systray_message().

◆ locale_from_utf8()

char * locale_from_utf8 ( char *  utf8str)

locale_from_utf8 - convert utf8 to active codepage must be freed by the caller

Parameters
*utf8str- Pointer to char to convert
Returns
*char - the converted char in locale format

Definition at line 48 of file xwidget-linux.c.

48 {
49 char *s_to = NULL;
50 asprintf(&s_to, "%s",utf8str);
51 return s_to;
52}
int asprintf(char *strp[], const char *fmt,...)
Definition xasprintf.c:36

◆ os_adjustment_callback()

void os_adjustment_callback ( void *  w_,
void *  user_data 
)

os_adjustment_callback - called when a adjustment value have changed used internal for redraw the Widget_t

Parameters
*w_- Pointer to the widget
*user_data- additional user data or NULL

Definition at line 737 of file xwidget-linux.c.

737 {
738 Widget_t *w = (Widget_t *)w_;
739 transparent_draw(w, user_data);
740}
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
void transparent_draw(void *wid, void *user_data)
transparent_draw - copy parent surface to child surface you usaualy didn't need to call this,...
Definition xwidget.c:449

◆ os_close_display()

void os_close_display ( Display dpy)

os_close_display - Close connection to the used display

Parameters
*dpy- Display to close

Definition at line 58 of file xwidget-linux.c.

58 {
59 XCloseDisplay(dpy);
60}

◆ os_create_main_window_and_surface()

void os_create_main_window_and_surface ( Widget_t w,
Xputty app,
Window  win,
int  x,
int  y,
int  width,
int  height 
)

os_create_main_window_and_surface - create a Widget_t with a acairo surface this function is used mainly internal on create_window()

Parameters
*w- the Widget_t to create
*app- the Xputty struct the Widget_t belongs to
*win- the Parent Window were the Widget_t belongs to
x,y- the position related to the Parent Window
*width,*height- the Widget_t size

Definition at line 122 of file xwidget-linux.c.

123 {
124 XSetWindowAttributes attributes;
125 attributes.save_under = True;
126 attributes.override_redirect = 0;
127
128 long event_mask = StructureNotifyMask|ExposureMask|KeyPressMask
129 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
130 |ButtonPressMask|Button1MotionMask;
131
132
133
134 w->widget = XCreateWindow(app->dpy, win , x, y, width, height, 0,
135 CopyFromParent, InputOutput, CopyFromParent,
136 CopyFromParent, &attributes);
137 debug_print("XCreateWindow\n");
138
139 XSetLocaleModifiers("");
140 w->xim = XOpenIM(app->dpy, 0, 0, 0);
141 if(!w->xim){
142 XSetLocaleModifiers("@im=none");
143 w->xim = XOpenIM(app->dpy, 0, 0, 0);
144 }
145
146 w->xic = XCreateIC(w->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
147 XNClientWindow, w->widget, XNFocusWindow, w->widget, NULL);
148
149 XSetICFocus(w->xic);
150
151 XSelectInput(app->dpy, w->widget, event_mask);
152
153 os_set_window_min_size(w, width/2, height/2, width, height);
154
155 w->surface = cairo_xlib_surface_create (app->dpy, w->widget,
156 DefaultVisual(app->dpy, DefaultScreen(app->dpy)), width, height);
157}
XIM xim
Definition xwidget.h:503
cairo_surface_t * surface
Definition xwidget.h:483
XIC xic
Definition xwidget.h:501
void os_set_window_min_size(Widget_t *w, int min_width, int min_height, int base_width, int base_height)
os_set_window_min_size - Set the min and base size of a Widget_t

◆ os_create_widget_window_and_surface()

void os_create_widget_window_and_surface ( Widget_t w,
Xputty app,
Widget_t parent,
int  x,
int  y,
int  width,
int  height 
)

os_create_main_widget_and_surface - create a Widget_t with a acairo surface this function is used mainly internal on create_widget()

Parameters
*w- the Widget_t to create
*app- the Xputty struct the Widget_t belongs to
*parent- the Parent Widget_t were the Widget_t belongs to
x,y- the position related to the Parent Widget_t
*width,*height- the Widget_t size

Definition at line 159 of file xwidget-linux.c.

160 {
161 XSetWindowAttributes attributes;
162 attributes.save_under = True;
163 attributes.override_redirect = True;
164
165 long event_mask = StructureNotifyMask|ExposureMask|KeyPressMask
166 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
167 |ButtonPressMask|Button1MotionMask;
168
169
170
171 w->widget = XCreateWindow(app->dpy, parent->widget , x, y, width, height, 0,
172 CopyFromParent, InputOutput, CopyFromParent,
173 CopyFromParent|CWOverrideRedirect, &attributes);
174 debug_print("XCreateWindow\n");
175
176 XSetLocaleModifiers("");
177 w->xim = XOpenIM(app->dpy, 0, 0, 0);
178 if(!w->xim){
179 XSetLocaleModifiers("@im=none");
180 w->xim = XOpenIM(app->dpy, 0, 0, 0);
181 }
182
183 w->xic = XCreateIC(w->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
184 XNClientWindow, w->widget, XNFocusWindow, w->widget, NULL);
185
186 XSetICFocus(w->xic);
187
188 XSelectInput(app->dpy, w->widget, event_mask);
189
190 w->surface = cairo_xlib_surface_create (app->dpy, w->widget,
191 DefaultVisual(app->dpy, DefaultScreen(app->dpy)), width, height);
192}

◆ os_destroy_window()

void os_destroy_window ( Widget_t w)

os_destroy_window - destroy a widget (close and remove from processing)

Parameters
*w- widget to destroy

Definition at line 62 of file xwidget-linux.c.

62 {
63 if (w->xic) XDestroyIC(w->xic);
64 if (w->xim) XCloseIM(w->xim);
65 XUnmapWindow(w->app->dpy, w->widget);
66 XDestroyWindow(w->app->dpy, w->widget);
67}

◆ os_expose_widget()

void os_expose_widget ( Widget_t w)

os_expose_widget - Draw the the back buffer to the Widget_t surface

Parameters
*w- Pointer to the widget

Definition at line 222 of file xwidget-linux.c.

222 {
223 XEvent exp;
224 memset(&exp, 0, sizeof(exp));
225 exp.type = Expose;
226 exp.xexpose.window = w->widget;
227 XSendEvent(w->app->dpy, w->widget, False, ExposureMask, (XEvent *)&exp);
228}
Window window

◆ os_free_pixmap()

void os_free_pixmap ( Widget_t w,
Pixmap  pixmap 
)

os_free_pixmap - Free the memory used by a Pixmap only Linux, stub otherwise

Parameters
*w- Pointer to the widget
pixmap- the pixmap to be freed

Definition at line 805 of file xwidget-linux.c.

805 {
806 XFreePixmap(w->app->dpy, pixmap);
807}

◆ os_get_home_dir()

char * os_get_home_dir ( )

os_get_home_dir - get the users home directory

Returns
*char - return the users home directory must be freed by the caller

Definition at line 791 of file xwidget-linux.c.

791 {
792 char *pPath = NULL;
793 asprintf(&pPath, "%s", getenv("HOME"));
794 assert(pPath != NULL);
795 return pPath;
796}

◆ os_get_keyboard_input()

bool os_get_keyboard_input ( Widget_t w,
XKeyEvent key,
char *  buf,
size_t  bufsize 
)

os_ get_keyboard_input - Get the Keyboard input and convert it to utf8

Parameters
*w- Pointer to the widget
*key- the XKeyEvent
*buf- the buffer to write the key in utf8 format
bufsize- the max buffer size to write to
Returns
bool - retrun true when the char is written to the buffer false on error

Definition at line 798 of file xwidget-linux.c.

798 {
799 Status status;
800 KeySym keysym;
801 Xutf8LookupString(w->xic, key, buf, bufsize - 1, &keysym, &status);
802 return (status == XLookupChars || status == XLookupBoth);
803}
XID KeySym

◆ os_get_root_window()

Window os_get_root_window ( Xputty main,
int  flag 
)

os_get_root_window - get a pointer to the root window (desktop)

Parameters
*main- pointer to the Xputty struct
flag- Could be IS_WIDGET for NO decorated windows (popup etc.)
  • or IS_WINDOW for decorated TopLevel Windows (Dialogs, MainWindow, etc)
Returns
WINDOW - return pointer to the parent Window to use

Definition at line 69 of file xwidget-linux.c.

69 {
70 return DefaultRootWindow(main->dpy);
71}

Referenced by os_show_tooltip().

◆ os_get_screen_height()

int os_get_screen_height ( Widget_t w)

os_get_screen_height - Get the height of the used Display

Parameters
*w- Pointer to the widget
Returns
int - the height of the Display

Definition at line 776 of file xwidget-linux.c.

776 {
777 int snum = DefaultScreen(w->app->dpy);
778 return DisplayHeight(w->app->dpy, snum);
779}

◆ os_get_screen_width()

int os_get_screen_width ( Widget_t w)

os_get_screen_width - Get the width of the used Display

Parameters
*w- Pointer to the widget
Returns
int - the width of the Display

Definition at line 781 of file xwidget-linux.c.

781 {
782 int snum = DefaultScreen(w->app->dpy);
783 return DisplayWidth(w->app->dpy, snum);
784}

◆ os_get_surface_size()

void os_get_surface_size ( cairo_surface_t *  surface,
int *  width,
int *  height 
)

os_get_surface_size - get the size of the cairo surface

Parameters
*surface- the cairo surface
*width,*height- (Pointer) to get the size

Definition at line 113 of file xwidget-linux.c.

113 {
114 *width = cairo_xlib_surface_get_width(surface);
115 *height = cairo_xlib_surface_get_height(surface);
116}

◆ os_get_window_metrics()

void os_get_window_metrics ( Widget_t w,
Metrics_t metrics 
)

os_get_window_metrics - Get the Merics_t struct related to a Widget_t

Parameters
*w- Pointer to the widget
*metrics- Pointer to the Metrics_t struct to hold the info for widget

Definition at line 80 of file xwidget-linux.c.

80 {
81 Widget_t *wid = (Widget_t*)w_;
82 XWindowAttributes attrs;
83 XGetWindowAttributes(wid->app->dpy, (Window)wid->widget, &attrs);
84 metrics->x = attrs.x;
85 metrics->y = attrs.y;
86 metrics->width = attrs.width;
87 metrics->height = attrs.height;
88 metrics->visible = (attrs.map_state == IsViewable);
89}
HWND Window

◆ os_grab_pointer()

int os_grab_pointer ( Widget_t w)

os_grab_pointer - grab the mouse pointer. Works only on linux

Parameters
*w- Pointer to the widget which will grab the mouse
Returns
int - Return 0 on error

Definition at line 742 of file xwidget-linux.c.

742 {
743 return XGrabPointer(w->app->dpy, DefaultRootWindow(w->app->dpy), True,
744 ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
745 GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
746
747}

◆ os_init_dnd()

void os_init_dnd ( Xputty main)

os_init_dnd - register a Widget_t for handling drag and drop events only implemented on linux

Parameters
*main- pointer to the Xputty struct

Definition at line 1048 of file xwidget-linux.c.

1048 {
1049 main->dnd_source_window = 0;
1050 main->dnd_version = 5;
1051 main->XdndAware = XInternAtom (main->dpy, "XdndAware", False);
1052 main->XdndTypeList = XInternAtom (main->dpy, "XdndTypeList", False);
1053 main->XdndSelection = XInternAtom (main->dpy, "XdndSelection", False);
1054 main->XdndStatus = XInternAtom (main->dpy, "XdndStatus", False);
1055 main->XdndEnter = XInternAtom (main->dpy, "XdndEnter", False);
1056 main->XdndPosition = XInternAtom (main->dpy, "XdndPosition", False);
1057 main->XdndLeave = XInternAtom (main->dpy, "XdndLeave", False);
1058 main->XdndDrop = XInternAtom (main->dpy, "XdndDrop", False);
1059 main->XdndActionCopy = XInternAtom (main->dpy, "XdndActionCopy", False);
1060 main->XdndFinished = XInternAtom (main->dpy, "XdndFinished", False);
1061 main->dnd_type_uri = XInternAtom (main->dpy, "text/uri-list", False);
1062 main->dnd_type_text = XInternAtom (main->dpy, "text/plain", False);
1063 main->dnd_type_utf8 = XInternAtom (main->dpy, "UTF8_STRING", False);
1064 main->dnd_type = None;
1065
1066 main->selection = XInternAtom(main->dpy, "CLIPBOARD", 0);
1067 main->targets_atom = XInternAtom(main->dpy, "TARGETS", 0);
1068 main->text_atom = XInternAtom(main->dpy, "TEXT", 0);
1069 main->UTF8 = XInternAtom(main->dpy, "UTF8_STRING", 1);
1070 if (main->UTF8 == None) main->UTF8 = XA_STRING;
1071}
Atom text_atom
Definition xputty.h:280
Atom XdndActionCopy
Definition xputty.h:270
Atom XdndPosition
Definition xputty.h:267
Atom UTF8
Definition xputty.h:281
Atom XdndEnter
Definition xputty.h:266
Atom targets_atom
Definition xputty.h:279
Atom XdndFinished
Definition xputty.h:271
Atom XdndAware
Definition xputty.h:262
Atom XdndStatus
Definition xputty.h:265
Atom XdndDrop
Definition xputty.h:269
Atom XdndLeave
Definition xputty.h:268

◆ os_is_directory()

bool os_is_directory ( const char *  filename)

os_is directory - check if a given path is a directory or a file

Parameters
*filename- the Path to check
Returns
bool - return true if path is directory, otrherwise false

Definition at line 786 of file xwidget-linux.c.

786 {
787 struct stat sb;
788 return (stat(filename, &sb) == 0 && S_ISDIR(sb.st_mode));
789}

◆ os_main_run()

void os_main_run ( Xputty main)

os_main_run - start the event loop

Parameters
*main- pointer to the Xputty struct

Definition at line 845 of file xwidget-linux.c.

845 {
846 Widget_t * wid = main->childlist->childs[0];
847 Atom WM_DELETE_WINDOW;
848 WM_DELETE_WINDOW = XInternAtom(main->dpy, "WM_DELETE_WINDOW", True);
849 XSetWMProtocols(main->dpy, wid->widget, &WM_DELETE_WINDOW, 1);
850
851 XEvent xev;
852 int ew;
853 Widget_t * w = NULL;
854
855 while (main->run && (XNextEvent(main->dpy, &xev)>=0)) {
856 if (XFilterEvent(&xev, None)) continue;
857 ew = childlist_find_widget(main->childlist, xev.xany.window);
858 if(ew >= 0) {
859 w = main->childlist->childs[ew];
860 w->event_callback(w, &xev, main, NULL);
861 }
862
863 switch (xev.type) {
864 case ButtonPress:
865 {
866 bool is_item = False;
867 if(main->submenu != NULL) {
869 Widget_t *slider = main->submenu->childlist->childs[1];
870 if (xev.xbutton.window == slider->widget) {
871 break;
872 }
873 Widget_t *view_port = main->submenu->childlist->childs[0];
874 int i = view_port->childlist->elem-1;
875 for(;i>-1;i--) {
876 Widget_t *w = view_port->childlist->childs[i];
877 if (xev.xbutton.window == w->widget) {
878 is_item = True;
879 break;
880 }
881 }
882 }
883 }
884 if(main->hold_grab != NULL && main->hold_grab->flags & IS_POPUP) {
886 Widget_t *slider = main->hold_grab->childlist->childs[1];
887 if (xev.xbutton.window == slider->widget) {
888 break;
889 }
890 Widget_t *view_port = main->hold_grab->childlist->childs[0];
891 int i = view_port->childlist->elem-1;
892 for(;i>-1;i--) {
893 Widget_t *w = view_port->childlist->childs[i];
894 if (xev.xbutton.window == w->widget) {
895 is_item = True;
896 break;
897 }
898 }
899 if (xev.xbutton.window == view_port->widget) is_item = True;
900 }
901 if (!is_item) {
902 XUngrabPointer(main->dpy,CurrentTime);
903 widget_hide(main->hold_grab);
904 main->hold_grab = NULL;
905 }
906 } else if(main->hold_grab != NULL && ((main->hold_grab->flags & IS_POPUP) == 0)) {
907 main->hold_grab->func.button_press_callback(main->hold_grab, &xev.xbutton, NULL);
908 }
909 }
910 break;
911 case ButtonRelease:
912 {
913 if(main->hold_grab != NULL && ((main->hold_grab->flags & IS_POPUP) == 0)) {
914 main->hold_grab->func.button_release_callback(main->hold_grab, &xev.xbutton, NULL);
915 }
916 }
917 break;
918 case KeyPress:
919 {
920 if (main->key_snooper != NULL && xev.xkey.window != main->key_snooper->widget) {
921 main->key_snooper->func.key_press_callback(main->key_snooper, &xev.xkey, NULL);
922 }
923 }
924 break;
925 case KeyRelease:
926 {
927 if (main->key_snooper != NULL && xev.xkey.window != main->key_snooper->widget) {
928 main->key_snooper->func.key_release_callback(main->key_snooper, &xev.xkey, NULL);
929 }
930 }
931 break;
932 case ClientMessage:
933 {
934 if (xev.xclient.data.l[0] == (long int)WM_DELETE_WINDOW &&
935 xev.xclient.window == wid->widget) {
936 main->run = false;
937 } else if (xev.xclient.data.l[0] == (long int)WM_DELETE_WINDOW) {
938 int i = childlist_find_widget(main->childlist, xev.xclient.window);
939 if(i<1) return;
940 Widget_t *w = main->childlist->childs[i];
941 if(w->flags & HIDE_ON_DELETE) widget_hide(w);
942 else destroy_widget(main->childlist->childs[i],main);
943 }
944 break;
945 }
946 }
947 }
948}
Widget_t ** childs
Definition xchildlist.h:51
evfunc button_release_callback
Definition xwidget.h:101
evfunc key_release_callback
Definition xwidget.h:105
evfunc key_press_callback
Definition xwidget.h:104
evfunc button_press_callback
Definition xwidget.h:100
vfunc event_callback
Definition xwidget.h:479
Childlist_t * childlist
Definition xwidget.h:499
long long flags
Definition xwidget.h:461
bool run
Definition xputty.h:256
Widget_t * hold_grab
Definition xputty.h:238
Childlist_t * childlist
Definition xputty.h:230
Widget_t * submenu
Definition xputty.h:242
Widget_t * key_snooper
Definition xputty.h:240
int childlist_find_widget(Childlist_t *childlist, Window child_window)
childlist_find_widget - find a child Widget_t in a the childlist by given the Window id
Definition xchildlist.c:79
int childlist_has_child(Childlist_t *childlist)
childlist_has_child - check if a Widget_t Childlist_t contain a child
Definition xchildlist.c:89
@ HIDE_ON_DELETE
Definition xwidget.h:412
@ IS_POPUP
Definition xwidget.h:392
void widget_hide(Widget_t *w)
widget_hide - unmap/hide a Widget_t
Definition xwidget.c:368
void destroy_widget(Widget_t *w, Xputty *main)
destroy_widget - destroy a widget When a Widget_t receive a destroy_widget() call,...
Definition xwidget.c:86

◆ os_move_window()

void os_move_window ( Display dpy,
Widget_t w,
int  x,
int  y 
)

os_move_window - Move a Widget_t

Parameters
*dpy- Pointer to the Display the widget belongs to
*w- Pointer to the widget
x,y- the point to move to

Definition at line 105 of file xwidget-linux.c.

105 {
106 XMoveWindow(dpy,w->widget, x, y);
107}

◆ os_open_display()

Display * os_open_display ( char *  display_name)

os_open_display - Connect to the display to use

Parameters
*display_name- Display name could be 0 for default
Returns
Display - return pointer to the Display struct

Definition at line 54 of file xwidget-linux.c.

54 {
55 return XOpenDisplay(display_name);
56}

◆ os_quit()

void os_quit ( Widget_t w)

os_quit - quit the main loop and free all used memory

Parameters
*w- Pointer to the widget request the quit call

Definition at line 809 of file xwidget-linux.c.

809 {
810 //Atom WM_DELETE_WINDOW = XInternAtom(w->app->dpy, "WM_DELETE_WINDOW", True);
811 Atom WM_DELETE_WINDOW = os_register_wm_delete_window(w);
812 XClientMessageEvent xevent;
813 xevent.type = ClientMessage;
814 xevent.message_type = WM_DELETE_WINDOW;
815 xevent.display = w->app->dpy;
816 xevent.window = get_toplevel_widget(w->app)->widget;
817 xevent.format = 16;
818 xevent.data.l[0] = WM_DELETE_WINDOW;
819 XSendEvent(w->app->dpy, w->widget, 0, 0, (XEvent *)&xevent);
820}
Atom os_register_wm_delete_window(Widget_t *wid)
os_register_wm_delete_window - Get the needed Atom to send a widget delete message
Widget_t * get_toplevel_widget(Xputty *main)
*get_toplevel_widget - get pointer to the top level Widget_t
Definition xwidget.c:441

◆ os_quit_widget()

void os_quit_widget ( Widget_t w)

os_quit_widget - remove a Widget_t from the main loop and free it's used memory

Parameters
*w- Pointer to the widget request the quit call

Definition at line 822 of file xwidget-linux.c.

822 {
823 Atom QUIT_WIDGET = os_register_widget_destroy(w);
824 XClientMessageEvent xevent;
825 xevent.type = ClientMessage;
826 xevent.message_type = QUIT_WIDGET;
827 xevent.display = w->app->dpy;
828 xevent.window = w->widget;
829 xevent.format = 16;
830 xevent.data.l[0] = 1;
831 XSendEvent(w->app->dpy, w->widget, 0, 0, (XEvent *)&xevent);
832}
Atom os_register_widget_destroy(Widget_t *wid)
os_register_widget_destroy - Get the needed Atom to send a widget destroy message

◆ os_register_widget_destroy()

Atom os_register_widget_destroy ( Widget_t wid)

os_register_widget_destroy - Get the needed Atom to send a widget destroy message

Parameters
*wid- Pointer to the widget request the quit call
Returns
ATOM - ATOM on linux, DWORD on windows

Definition at line 841 of file xwidget-linux.c.

841 {
842 return XInternAtom(wid->app->dpy, "WIDGET_DESTROY", False);
843}

Referenced by os_quit_widget().

◆ os_register_wm_delete_window()

Atom os_register_wm_delete_window ( Widget_t wid)

os_register_wm_delete_window - Get the needed Atom to send a widget delete message

Parameters
*wid- Pointer to the widget request the quit call
Returns
ATOM - ATOM on linux, DWORD on windows

Definition at line 834 of file xwidget-linux.c.

834 {
835 Atom WM_DELETE_WINDOW;
836 WM_DELETE_WINDOW = XInternAtom(wid->app->dpy, "WM_DELETE_WINDOW", True);
837 XSetWMProtocols(wid->app->dpy, wid->widget, &WM_DELETE_WINDOW, 1);
838 return WM_DELETE_WINDOW;
839}

Referenced by os_quit().

◆ os_resize_window()

void os_resize_window ( Display dpy,
Widget_t w,
int  x,
int  y 
)

os_resize_window - Resize a Widget_t

Parameters
*dpy- Pointer to the Display the widget belongs to
*w- Pointer to the Widget_t
x,y- the new size

Definition at line 109 of file xwidget-linux.c.

109 {
110 XResizeWindow(dpy, w->widget, x, y);
111}

◆ os_run_embedded()

void os_run_embedded ( Xputty main)

os_run_embedded - the event handling when run embedded on windows all messges goes into WndProc, so stub here

Parameters
*main- pointer to the Xputty struct

Definition at line 950 of file xwidget-linux.c.

950 {
951
952 XEvent xev;
953 int ew = -1;
954
955 while (XPending(main->dpy) > 0) {
956 XNextEvent(main->dpy, &xev);
957 if (xev.type == ClientMessage || xev.type == SelectionNotify) {
958 Widget_t * w = main->childlist->childs[0];
959 w->event_callback(w, &xev, main, NULL);
960 }
961 ew = childlist_find_widget(main->childlist, xev.xany.window);
962 if(ew >= 0) {
963 Widget_t * w = main->childlist->childs[ew];
964 w->event_callback(w, &xev, main, NULL);
965 }
966 switch (xev.type) {
967 case ButtonPress:
968 {
969 bool is_item = False;
970 if(main->submenu != NULL) {
972 Widget_t *slider = main->submenu->childlist->childs[1];
973 if (xev.xbutton.window == slider->widget) {
974 break;
975 }
976 Widget_t *view_port = main->submenu->childlist->childs[0];
977 int i = view_port->childlist->elem-1;
978 for(;i>-1;i--) {
979 Widget_t *w = view_port->childlist->childs[i];
980 if (xev.xbutton.window == w->widget) {
981 is_item = True;
982 break;
983 }
984 }
985 }
986 }
987 if(main->hold_grab != NULL && main->hold_grab->flags & IS_POPUP) {
989 Widget_t *slider = main->hold_grab->childlist->childs[1];
990 if (xev.xbutton.window == slider->widget) {
991 break;
992 }
993 Widget_t *view_port = main->hold_grab->childlist->childs[0];
994 int i = view_port->childlist->elem-1;
995 for(;i>-1;i--) {
996 Widget_t *w = view_port->childlist->childs[i];
997 if (xev.xbutton.window == w->widget) {
998 is_item = True;
999 break;
1000 }
1001 }
1002 if (xev.xbutton.window == view_port->widget) is_item = True;
1003 }
1004 if (!is_item) {
1005 XUngrabPointer(main->dpy,CurrentTime);
1006 widget_hide(main->hold_grab);
1007 main->hold_grab = NULL;
1008 }
1009 } else if(main->hold_grab != NULL && ((main->hold_grab->flags & IS_POPUP) == 0)) {
1010 main->hold_grab->func.button_press_callback(main->hold_grab, &xev.xbutton, NULL);
1011 }
1012 }
1013 break;
1014 case ButtonRelease:
1015 {
1016 if(main->hold_grab != NULL && ((main->hold_grab->flags & IS_POPUP) == 0)) {
1017 main->hold_grab->func.button_release_callback(main->hold_grab, &xev.xbutton, NULL);
1018 }
1019 }
1020 break;
1021 case KeyPress:
1022 {
1023 if (main->key_snooper != NULL && xev.xkey.window != main->key_snooper->widget) {
1024 main->key_snooper->func.key_press_callback(main->key_snooper, &xev.xkey, NULL);
1025 }
1026 }
1027 break;
1028 case KeyRelease:
1029 {
1030 if (main->key_snooper != NULL && xev.xkey.window != main->key_snooper->widget) {
1031 main->key_snooper->func.key_release_callback(main->key_snooper, &xev.xkey, NULL);
1032 }
1033 }
1034 break;
1035 case ClientMessage:
1036 if (xev.xclient.data.l[0] == (long int)XInternAtom(main->dpy, "WM_DELETE_WINDOW", True) ) {
1037 int i = childlist_find_widget(main->childlist, xev.xclient.window);
1038 if(i<1) return;
1039 Widget_t *w = main->childlist->childs[i];
1040 if(w->flags & HIDE_ON_DELETE) widget_hide(w);
1041 else destroy_widget(w, main);
1042 }
1043 break;
1044 }
1045 }
1046}

◆ os_send_button_press_event()

void os_send_button_press_event ( Widget_t w)

os_send_button_press_event - Send a button press event to a Widget_t see XButtonEvent

Parameters
*w- Pointer to the widget

Definition at line 641 of file xwidget-linux.c.

641 {
642 XEvent event;
643 memset(&event, 0, sizeof(XEvent));
644 XWindowAttributes attr;
645 XGetWindowAttributes(w->app->dpy, w->widget, &attr);
646 event.type = ButtonPress;
647 event.xbutton.same_screen = true;
648 event.xbutton.root = None;
649 event.xbutton.window = w->widget;
650 event.xbutton.subwindow = None;
651 event.xbutton.x = 1;
652 event.xbutton.y = 1;
653 event.xbutton.x_root = attr.x;
654 event.xbutton.y_root = attr.y;
655 event.xbutton.state = 0;
656 event.xbutton.button = Button1;
657 XSendEvent(w->app->dpy, PointerWindow, True, ButtonPressMask, &event);
658}

◆ os_send_button_release_event()

void os_send_button_release_event ( Widget_t w)

os_send_button_release_event - Send a button release event to a Widget_t see XButtonEvent

Parameters
*w- Pointer to the widget

Definition at line 660 of file xwidget-linux.c.

660 {
661 XEvent event;
662 memset(&event, 0, sizeof(XEvent));
663 XWindowAttributes attr;
664 XGetWindowAttributes(w->app->dpy, w->widget, &attr);
665 event.type = ButtonRelease;
666 event.xbutton.same_screen = true;
667 event.xbutton.root = None;
668 event.xbutton.window = w->widget;
669 event.xbutton.subwindow = None;
670 event.xbutton.x = 1;
671 event.xbutton.y = 1;
672 event.xbutton.x_root = attr.x;
673 event.xbutton.y_root = attr.y;
674 event.xbutton.state = 0;
675 event.xbutton.button = Button1;
676 XSendEvent(w->app->dpy, PointerWindow, True, ButtonReleaseMask, &event);
677}

◆ os_send_configure_event()

void os_send_configure_event ( Widget_t w,
int  x,
int  y,
int  width,
int  height 
)

os_send_configure_event - Send a configure event to a Widget_t

Parameters
*w- Pointer to the widget
x,y- the position to set
width,height- the size to set

Definition at line 623 of file xwidget-linux.c.

623 {
624 XConfigureEvent notify;
625 memset(&notify, 0, sizeof(notify));
626 notify.type = ConfigureNotify;
627 notify.display = w->app->dpy;
628 notify.send_event = True;
629 notify.event = w->widget;
630 notify.window = w->widget;
631 notify.x = x;
632 notify.y = y;
633 notify.width = width;
634 notify.height = height;
635 notify.border_width = 0;
636 notify.above = None;
637 notify.override_redirect = 1;
638 XSendEvent( w->app->dpy, w->widget, true, StructureNotifyMask, (XEvent*)&notify );
639}

◆ os_send_systray_message()

void os_send_systray_message ( Widget_t w)

os_send_send_systray_message - Send a systray event to a Widget_t only working on Linux for now

Parameters
*w- Pointer to the widget

Definition at line 679 of file xwidget-linux.c.

679 {
680 XEvent event;
681 Screen *xscreen;
682 char buf[256];
683 buf[0]=0;
684
685 xscreen=DefaultScreenOfDisplay(w->app->dpy);
686 sprintf(buf,"_NET_SYSTEM_TRAY_S%d",XScreenNumberOfScreen (xscreen));
687 Atom selection_atom = XInternAtom (w->app->dpy,buf,0);
688
689 Window tray = XGetSelectionOwner (w->app->dpy,selection_atom);
690 Atom visualatom = XInternAtom(w->app->dpy, "_NET_SYSTEM_TRAY_VISUAL", False);
691 VisualID value = XVisualIDFromVisual(DefaultVisual(w->app->dpy, DefaultScreen(w->app->dpy)));
692 XChangeProperty(w->app->dpy, w->widget, visualatom, XA_VISUALID, 32,
693 PropModeReplace, (unsigned char*)&value, 1);
694
695 if ( tray != None) {
696 XSelectInput (w->app->dpy,tray,StructureNotifyMask);
697 /* get tray color and set as background */
698 XColor c;
699 XWindowAttributes attrs;
700 XGetWindowAttributes(w->app->dpy, DefaultRootWindow(w->app->dpy), &attrs);
701
702 XImage *image = NULL;
704 image = XGetImage(w->app->dpy, DefaultRootWindow(w->app->dpy),
705 attrs.width -2, attrs.height -2, 1, 1, AllPlanes, XYPixmap);
706 XSetErrorHandler(default_error_handler);
707 if (image) {
708 c.pixel = XGetPixel(image, 0, 0);
709 XQueryColor (w->app->dpy, DefaultColormap(w->app->dpy, DefaultScreen (w->app->dpy)), &c);
710 double r = (double)c.red/65535.0;
711 double g = (double)c.green/65535.0;
712 double b = (double)c.blue/65535.0;
713 set_systray_color(w->app, r, g, b, 1.0);
714 XDestroyImage(image);
715 }
716 }
717
718 memset(&event, 0, sizeof(event));
719 event.xclient.type = ClientMessage;
720 event.xclient.window = tray;
721 event.xclient.message_type = XInternAtom (w->app->dpy, "_NET_SYSTEM_TRAY_OPCODE", False );
722 event.xclient.format = 32;
723 event.xclient.data.l[0] = CurrentTime;
724 event.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
725 event.xclient.data.l[2] = w->widget;
726 event.xclient.data.l[3] = 0;
727 event.xclient.data.l[4] = 0;
728
729 XSendEvent(w->app->dpy, tray, False, NoEventMask, &event);
730}
void set_systray_color(Xputty *main, double r, double g, double b, double a)
set_systray_color - set the systray background color
Definition xcolor.c:300
int intern_error_handler(Display *dpy, XErrorEvent *e)
int(* default_error_handler)(Display *dpy, XErrorEvent *e)

◆ os_set_input_mask()

void os_set_input_mask ( Widget_t w)

os_set_input_mask - set the Event mask to a Widget_t only work on linux, stub on Windows

Parameters
*w- Pointer to the widget which will grab the mouse

Definition at line 749 of file xwidget-linux.c.

749 {
750 XSelectInput(w->app->dpy, w->widget,StructureNotifyMask|ExposureMask|KeyPressMask
751 |EnterWindowMask|LeaveWindowMask|ButtonReleaseMask
752 |ButtonPressMask|Button1MotionMask|PointerMotionMask);
753}

◆ os_set_title()

void os_set_title ( Widget_t w,
const char *  title 
)

os_set_title - Set the title of a Widget_t

Parameters
*w- Pointer to the widget
title- the title to set

Definition at line 194 of file xwidget-linux.c.

194 {
195 XStoreName(w->app->dpy, w->widget, title);
196 XChangeProperty(w->app->dpy, w->widget,
197 XInternAtom(w->app->dpy, "_NET_WM_NAME", False),
198 XInternAtom(w->app->dpy, "UTF8_STRING", False),
199 8, PropModeReplace, (unsigned char *) title,
200 strlen(title));
201}

◆ os_set_transient_for_hint()

void os_set_transient_for_hint ( Widget_t parent,
Widget_t w 
)

os_set_ transient_for_hint - set a Widget_t transient to a other Widget_t only work on linux, stub on Windows

Parameters
*parent- Pointer to the parent widget
*w- Pointer to the widget

Definition at line 771 of file xwidget-linux.c.

771 {
772
773 XSetTransientForHint(parent->app->dpy,w->widget,parent->widget);
774}

◆ os_set_widget_surface_size()

void os_set_widget_surface_size ( Widget_t w,
int  width,
int  height 
)

os_set_widget_surface_size - set the size of a Widget_t cairo surface

Parameters
*w- Pointer to the Widget_t the surface belongs to
*width,*height- the size to set

Definition at line 118 of file xwidget-linux.c.

118 {
119 cairo_xlib_surface_set_size(w->surface, width, height);
120}

◆ os_set_window_attrb()

void os_set_window_attrb ( Widget_t w)

os_set_window_attrb - set the attribute mask to a Widget_t only work on linux, stub on Windows

Parameters
*w- Pointer to the widget which will grab the mouse

Definition at line 755 of file xwidget-linux.c.

755 {
756 XSetWindowAttributes attributes;
757 attributes.override_redirect = True;
758 XChangeWindowAttributes(w->app->dpy, w->widget, CWOverrideRedirect, &attributes);
759
760 Atom window_type = XInternAtom(w->app->dpy, "_NET_WM_WINDOW_TYPE", False);
761 Atom window_type_popup = XInternAtom(w->app->dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
762 XChangeProperty(w->app->dpy, w->widget, window_type,
763 XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_type_popup,1 );
764
765 Atom window_state = XInternAtom(w->app->dpy, "_NET_WM_STATE", False);
766 Atom window_state_modal = XInternAtom(w->app->dpy, "_NET_WM_STATE_MODAL", False);
767 XChangeProperty(w->app->dpy, w->widget, window_state,
768 XA_ATOM, 32, PropModeReplace, (unsigned char *) &window_state_modal, 1);
769}

◆ os_set_window_min_size()

void os_set_window_min_size ( Widget_t w,
int  min_width,
int  min_height,
int  base_width,
int  base_height 
)

os_set_window_min_size - Set the min and base size of a Widget_t

Parameters
*w- Pointer to the widget
min_width,min_height- the min size to set
base_width,base_height- the base size to set

Definition at line 91 of file xwidget-linux.c.

92 {
93 XSizeHints* win_size_hints;
94 win_size_hints = XAllocSizeHints();
95 win_size_hints->flags = PMinSize|PBaseSize|PWinGravity;
96 win_size_hints->min_width = min_width;
97 win_size_hints->min_height = min_height;
98 win_size_hints->base_width = base_width;
99 win_size_hints->base_height = base_height;
100 win_size_hints->win_gravity = CenterGravity;
101 XSetWMNormalHints(w->app->dpy, w->widget, win_size_hints);
102 XFree(win_size_hints);
103}

Referenced by os_create_main_window_and_surface().

◆ os_show_tooltip()

void os_show_tooltip ( Widget_t wid,
Widget_t w 
)

os_show_tooltip - Show a tooltip of a Widget_t

Parameters
*wid- Pointer to the widget the tooltip belongs to
*w- the tooltip Widget_t

Definition at line 211 of file xwidget-linux.c.

211 {
212 unsigned int mask;
213 int x, y, rx, ry;
214 Window child, root;
215 XQueryPointer(wid->app->dpy, wid->widget, &root, &child, &rx, &ry, &x, &y, &mask);
216 int x1, y1;
217 os_translate_coords(wid, wid->widget, os_get_root_window(wid->app, IS_WIDGET), x, y, &x1, &y1);
218 XMoveWindow(w->app->dpy,w->widget,x1+10, y1-10);
219 XMapWindow(w->app->dpy, w->widget);
220}
Window os_get_root_window(Xputty *main, int flag)
os_get_root_window - get a pointer to the root window (desktop)
void os_translate_coords(Widget_t *w, Window from_window, Window to_window, int from_x, int from_y, int *to_x, int *to_y)
os_translate_coords - get x,y related to destination Window
@ IS_WIDGET
Definition xwidget.h:388

◆ os_translate_coords()

void os_translate_coords ( Widget_t w,
Window  from_window,
Window  to_window,
int  from_x,
int  from_y,
int *  to_x,
int *  to_y 
)

os_translate_coords - get x,y related to destination Window

Parameters
*w- Widget_t pointer
from_window- source Window
to_window- destination Window
from_x,from_y- point from the source Window
*to_x,*to_y- (Pointer) point in the destination Window

Definition at line 73 of file xwidget-linux.c.

74 {
75 Window child;
76 XTranslateCoordinates(w->app->dpy, from_window, to_window,
77 from_x, from_y, to_x, to_y, &child);
78}

Referenced by os_show_tooltip().

◆ os_transparent_draw()

void os_transparent_draw ( void *  w_,
void *  user_data 
)

os_transparent_draw - Draw the Widget_t to the back buffer

Parameters
*w_- Pointer to the widget
*user_data- additional user data or NULL

Definition at line 732 of file xwidget-linux.c.

732 {
733 Widget_t *w = (Widget_t *)w_;
734 transparent_draw(w, user_data);
735}

◆ os_widget_event_loop()

void os_widget_event_loop ( void *  w_,
void *  event,
Xputty main,
void *  user_data 
)

os_widget_event_loop - the Widget_t event loop on windows all messges goes into WndProc, so stub here

Parameters
*w_- Pointer to the widget
*event- the event to handle
*main- pointer to the Xputty struct
*user_data- additional user data could be NULL

Definition at line 230 of file xwidget-linux.c.

230 {
231 Widget_t *wid = (Widget_t*)w_;
232 XEvent *xev = (XEvent*)event;
233
234 switch(xev->type) {
235 case ConfigureNotify:
236 wid->func.configure_callback(w_, user_data);
237 //transparent_draw(w_, user_data);
238 debug_print("Widget_t ConfigureNotify \n");
239 break;
240
241 case VisibilityNotify:
242 wid->func.visibiliy_change_callback(w_, user_data);
243 debug_print("Widget_t VisibilityNotify \n");
244 break;
245
246 case Expose:
247 if (xev->xexpose.count == 0) {
248 if ((wid->flags & FAST_REDRAW) == 0) {
249 XEvent ev;
250 while (XCheckTypedWindowEvent(main->dpy, wid->widget, Expose, &ev)) {}
251 }
252 transparent_draw(w_, user_data);
253 debug_print("Widget_t Expose \n");
254 }
255 break;
256
257 case ButtonPress:
258 if (wid->state == 4) break;
259 if (wid->flags & HAS_TOOLTIP) hide_tooltip(wid);
260 _button_press(wid, &xev->xbutton, user_data);
261 debug_print("Widget_t ButtonPress %i\n", xev->xbutton.button);
262 break;
263
264 case ButtonRelease:
265 {
266 XButtonEvent *xbutton = &xev->xbutton;
267 _check_grab(wid, xbutton, main);
268 _check_submenu(wid, xbutton, main);
269 if (wid->state == 4) break;
270 if (xbutton->button == Button1) {
271 if ((wid->flags & IS_POPUP) == 0) {
272 if (xbutton->time < wid->double_click+300) {
273 wid->func.double_click_callback(wid, xbutton, user_data);
274 break;
275 }
276 wid->double_click = xbutton->time;
277 }
278 }
279 _has_pointer(wid, &xev->xbutton);
280 if(wid->flags & HAS_POINTER) wid->state = 1;
281 else wid->state = 0;
282 _check_enum(wid, xbutton);
283 wid->func.button_release_callback(w_, xbutton, user_data);
284 debug_print("Widget_t ButtonRelease %i\n", xev->xbutton.button);
285 }
286 break;
287
288 case KeyPress:
289 if (wid->state == 4) break;
290 _check_keymap(wid, xev->xkey);
291 wid->func.key_press_callback(w_, &xev->xkey, user_data);
292 debug_print("Widget_t KeyPress %u\n", xev->xkey.keycode);
293 break;
294
295 case KeyRelease:
296 {
297 if (wid->state == 4) break;
298 unsigned short is_retriggered = 0;
299 if(wid->flags & NO_AUTOREPEAT) {
300 char keys[32];
301 XQueryKeymap(main->dpy, keys);
302
303 if((keys[xev->xkey.keycode>>3] & (0x1 << (xev->xkey.keycode % 8))) &&
304 (xev->xkey.keycode > 119 || xev->xkey.keycode < 110)) {
305 is_retriggered = 1;
306 }
307 }
308 if (!is_retriggered) {
309 wid->func.key_release_callback(w_, &xev->xkey, user_data);
310 debug_print("Widget_t KeyRelease %u\n", xev->xkey.keycode);
311 }
312 }
313 break;
314
315 case LeaveNotify:
316 wid->flags &= ~HAS_FOCUS;
317 if (wid->state == 4) break;
318 if(!(xev->xcrossing.state & Button1Mask) &&
319 !(xev->xcrossing.state & Button2Mask) &&
320 !(xev->xcrossing.state & Button3Mask)) {
321 wid->state = 0;
322 wid->func.leave_callback(w_, user_data);
323 }
324 if (wid->flags & HAS_TOOLTIP) hide_tooltip(wid);
325 debug_print("Widget_t LeaveNotify \n");
326 break;
327
328 case EnterNotify:
329 wid->flags |= HAS_FOCUS;
330 if (wid->state == 4) break;
331 if(!(xev->xcrossing.state & Button1Mask) &&
332 !(xev->xcrossing.state & Button2Mask) &&
333 !(xev->xcrossing.state & Button3Mask)) {
334 wid->state = 1;
335 wid->func.enter_callback(w_, user_data);
336 if (wid->flags & HAS_TOOLTIP) show_tooltip(wid);
337 else _hide_all_tooltips(wid);
338 }
339 debug_print("Widget_t EnterNotify \n");
340 break;
341
342 case MotionNotify:
343 if (wid->state == 4) break;
344 if (xev->xmotion.state) {
345 adj_set_motion_state(wid, xev->xmotion.x, xev->xmotion.y);
346 }
347 wid->func.motion_callback(w_,&xev->xmotion, user_data);
348 debug_print("Widget_t MotionNotify x = %i Y = %i \n",xev->xmotion.x,xev->xmotion.y );
349 break;
350
351 case SelectionRequest:
352 if (xev->xselectionrequest.selection != main->selection) break;
353 send_to_clipboard(wid, xev);
354 break;
355 case SelectionClear:
356 break;
357 case SelectionNotify:
358 if (xev->xselection.property == None) {
359 wid->xpaste_callback(wid, NULL);
360 break;
361 }
362 if (xev->xselection.selection == main->selection) {
364 break;
365 }
366 debug_print("Widget_t SelectionNotify\n");
367 handle_drag_data(wid, xev);
368 break;
369
370 case ClientMessage:
371 if (xev->xclient.message_type == main->XdndPosition) {
372 debug_print( "XdndPosition\n");
373 send_dnd_status_event(wid, xev);
374 } else if (xev->xclient.message_type == main->XdndEnter) {
375 debug_print( "XdndEnter\n");
376 handle_dnd_enter(main, xev);
377 } else if (xev->xclient.message_type == main->XdndLeave) {
378 debug_print( "XdndLeave\n");
379 main->dnd_type = None;
380 main->dnd_source_window = 0;
381 main->dnd_version = 0;
382 } else if (xev->xclient.message_type == main->XdndDrop) {
383 if ((DND_SOURCE_WIN(xev) != main->dnd_source_window) ||
384 main->dnd_type == None || main->dnd_source_window == 0) {
385 break;
386 }
387 XConvertSelection(main->dpy, main->XdndSelection,
388 main->dnd_type, main->XdndSelection, wid->widget, CurrentTime);
389
390 send_dnd_finished_event(wid, xev);
391 } else if (xev->xclient.message_type == XInternAtom(wid->app->dpy, "WIDGET_DESTROY", 1)) {
392 int ch = childlist_has_child(wid->childlist);
393 if (ch) {
394 int i = ch;
395 for(;i>0;i--) {
396 quit_widget(wid->childlist->childs[i-1]);
397 }
398 quit_widget(wid);
399 } else {
400 destroy_widget(wid,main);
401 }
402 }
403 break;
404 default:
405 break;
406 }
407}
xevfunc configure_callback
Definition xwidget.h:86
xevfunc visibiliy_change_callback
Definition xwidget.h:98
evfunc double_click_callback
Definition xwidget.h:102
xevfunc leave_callback
Definition xwidget.h:88
evfunc motion_callback
Definition xwidget.h:103
xevfunc enter_callback
Definition xwidget.h:87
int state
Definition xwidget.h:511
xevfunc xpaste_callback
Definition xwidget.h:533
Time double_click
Definition xwidget.h:506
unsigned int state
int button
int keycode
void adj_set_motion_state(void *w, float x, float y)
adj_set_motion_state - internal use to set value and state of the Adjustment_t on mouse pointer movme...
void receive_paste_from_clipboard(Widget_t *w, XEvent *event)
receive_paste_from_clipboard - receive textbuffer from clipboard
void send_to_clipboard(Widget_t *w, XEvent *event)
send_to_clipboard - send textbuffer to clipboard on request
void send_dnd_status_event(Widget_t *w, XEvent *event)
send_dnd_status_event - notify the drag sender that prepared to recive the event
void handle_dnd_enter(Xputty *main, XEvent *event)
handle_drag_enter - handle drag event enter the Widget_t
void handle_drag_data(Widget_t *w, XEvent *event)
handle_drag_data - handle recived drag data
void quit_widget(Widget_t *w)
quit_widget - remove a widget from the processing loop
Definition xwidget.c:530
void show_tooltip(Widget_t *wid)
show_tooltip - check if a Widget_t have a tooltip, and show it, if a tooltip is available.
Definition xwidget.c:419
@ FAST_REDRAW
Definition xwidget.h:410
@ HAS_POINTER
Definition xwidget.h:402
@ NO_AUTOREPEAT
Definition xwidget.h:408
@ HAS_TOOLTIP
Definition xwidget.h:404
@ HAS_FOCUS
Definition xwidget.h:400
void hide_tooltip(Widget_t *wid)
hide_tooltip - check if a Widget_t have a tooltip, and hide it, if a tooltip is mapped.
Definition xwidget.c:430
void _hide_all_tooltips(Widget_t *wid)
_hide_all_tooltips - hide all active tooltips
void _check_enum(Widget_t *wid, XButtonEvent *xbutton)
_check_enum - internal check if Adjustment_t is of type CL_ENUM and handle events acordingly
void _check_grab(Widget_t *wid, XButtonEvent *xbutton, Xputty *main)
_check_grab - internal check if a Widgt_t holds a grab when a BUTTON_PRESS event occur....
void _button_press(Widget_t *wid, XButtonEvent *xbutton, void *user_data)
_button_press - internal check which button is pressed (BUTTON_PRESS)
void _check_submenu(Widget_t *wid, XButtonEvent *xbutton, Xputty *main)
_check_submenu - internal check if a Widgt_t is a submenu when a BUTTON_PRESS event occur....
void _check_keymap(void *w_, XKeyEvent xkey)
_check_keymap - check if key is in map, send requests if so
void _has_pointer(Widget_t *w, XButtonEvent *button)
_has_pointer - check if the widget has the pointer

◆ os_widget_hide()

void os_widget_hide ( Widget_t w)

os_widget_hide - Hide a Widget_t

Parameters
*w- Pointer to the widget to hide

Definition at line 207 of file xwidget-linux.c.

207 {
208 XUnmapWindow(w->app->dpy, w->widget);
209}

◆ os_widget_show()

void os_widget_show ( Widget_t w)

os_widget_show - Show a Widget_t

Parameters
*w- Pointer to the widget to show

Definition at line 203 of file xwidget-linux.c.

203 {
204 XMapWindow(w->app->dpy, w->widget);
205}

◆ receive_paste_from_clipboard()

void receive_paste_from_clipboard ( Widget_t w,
XEvent event 
)

receive_paste_from_clipboard - receive textbuffer from clipboard

Parameters
w- the Widget_t which requested the buffer
event- the event contain the request

Definition at line 566 of file xwidget-linux.c.

566 {
567 if(event->xselection.property) {
568 Atom target;
569 char * data = NULL;
570 int format;
571 unsigned long N, size;
572 XGetWindowProperty(event->xselection.display, event->xselection.requestor,
573 event->xselection.property, 0L,(~0L), 0, AnyPropertyType, &target,
574 &format, &size, &N,(unsigned char**)&data);
575 if(target == w->app->UTF8 || target == XA_STRING) {
576 free(w->app->ctext);
577 w->app->ctext = NULL;
578 w->app->ctext = (unsigned char*)strndup(data, size);
579 XFree(data);
580 }
581 XDeleteProperty(event->xselection.display, event->xselection.requestor, event->xselection.property);
582 w->xpaste_callback(w, (void*)&w->app->ctext);
583 }
584}

References Widget_t::app, Xputty::ctext, Xputty::UTF8, and Widget_t::xpaste_callback.

Referenced by os_widget_event_loop().

◆ request_paste_from_clipboard()

void request_paste_from_clipboard ( Widget_t w)

request_paste_from_clipboard - request textbuffer from clipboard

Parameters
w- the Widget_t to send the request

Definition at line 561 of file xwidget-linux.c.

561 {
562 Atom XSEL_DATA = XInternAtom(w->app->dpy, "XSEL_DATA", 0);
563 XConvertSelection(w->app->dpy, w->app->selection, w->app->UTF8, XSEL_DATA, w->widget, CurrentTime);
564}

References Widget_t::app, Xputty::dpy, Xputty::selection, Xputty::UTF8, and Widget_t::widget.

◆ send_dnd_finished_event()

void send_dnd_finished_event ( Widget_t w,
XEvent event 
)

send_dnd_finished_event - notify the drag sender that the event is handled

Parameters
w- the Widget_t handled the event
event- the drag event contain the drop data

Definition at line 540 of file xwidget-linux.c.

540 {
541 if (w->app->dnd_version < 2) {
542 return;
543 }
544 XEvent xev;
545 memset (&xev, 0, sizeof (XEvent));
546 xev.xany.type = ClientMessage;
547 xev.xany.display = w->app->dpy;
548 xev.xclient.window = w->app->dnd_source_window;
549 xev.xclient.message_type = w->app->XdndFinished;
550 xev.xclient.format = 32;
551 xev.xclient.data.l[0] = event->xany.window;
552 xev.xclient.data.l[1] = 1;
553 xev.xclient.data.l[2] = w->app->XdndActionCopy;
554 XSendEvent (w->app->dpy, w->app->dnd_source_window, False, NoEventMask, &xev);
555}

References Widget_t::app, Xputty::dnd_source_window, Xputty::dnd_version, Xputty::dpy, XEvent::window, Xputty::XdndActionCopy, and Xputty::XdndFinished.

Referenced by handle_drag_data(), and os_widget_event_loop().

◆ send_dnd_status_event()

void send_dnd_status_event ( Widget_t w,
XEvent event 
)

send_dnd_status_event - notify the drag sender that prepared to recive the event

Parameters
w- the Widget_t to recive the event
event- the drag event contain the drop data

Definition at line 524 of file xwidget-linux.c.

524 {
525 XEvent xev;
526 memset (&xev, 0, sizeof (XEvent));
527 xev.xany.type = ClientMessage;
528 xev.xany.display = w->app->dpy;
529 xev.xclient.window = w->app->dnd_source_window;
530 xev.xclient.message_type = w->app->XdndStatus;
531 xev.xclient.format = 32;
532 xev.xclient.data.l[0] = event->xany.window;
533 xev.xclient.data.l[1] = (w->app->dnd_type != None) ? 1 : 0;
534 xev.xclient.data.l[2] = DND_DROP_TIME(event);
535 xev.xclient.data.l[3] = 0;
536 xev.xclient.data.l[4] = w->app->XdndActionCopy;
537 XSendEvent (w->app->dpy, w->app->dnd_source_window, False, NoEventMask, &xev);
538}

References Widget_t::app, Xputty::dnd_source_window, Xputty::dnd_type, Xputty::dpy, XEvent::window, Xputty::XdndActionCopy, and Xputty::XdndStatus.

Referenced by os_widget_event_loop().

◆ send_to_clipboard()

void send_to_clipboard ( Widget_t w,
XEvent event 
)

send_to_clipboard - send textbuffer to clipboard on request

Parameters
w- the Widget_t to send the event
event- the event contain the request

Definition at line 595 of file xwidget-linux.c.

595 {
596 XSelectionRequestEvent * xsr = &event->xselectionrequest;
597 XSelectionEvent xev;
598 memset (&xev, 0, sizeof (XSelectionEvent));
599 int R = 0;
600 xev.type = SelectionNotify;
601 xev.display = xsr->display;
602 xev.requestor = xsr->requestor;
603 xev.selection = xsr->selection;
604 xev.time = xsr->time;
605 xev.target = xsr->target;
606 xev.property = xsr->property;
607 if (xev.target == w->app->targets_atom) {
608 R = XChangeProperty (xev.display, xev.requestor, xev.property, XA_ATOM, 32,
609 PropModeReplace, (unsigned char*)&w->app->UTF8, 1);
610 } else if (xev.target == XA_STRING || xev.target == w->app->text_atom) {
611 R = XChangeProperty(xev.display, xev.requestor, xev.property, XA_STRING, 8,
612 PropModeReplace, w->app->ctext, w->app->csize);
613 } else if (xev.target == w->app->UTF8) {
614 R = XChangeProperty(xev.display, xev.requestor, xev.property, w->app->UTF8, 8,
615 PropModeReplace, w->app->ctext, w->app->csize);
616 } else {
617 xev.property = None;
618 }
619 if ((R & 2) == 0) XSendEvent (w->app->dpy, xev.requestor, 0, 0, (XEvent *)&xev);
620 debug_print("send to clipboard %s\n", w->app->ctext);
621}

References Widget_t::app, Xputty::csize, Xputty::ctext, Xputty::dpy, Xputty::targets_atom, Xputty::text_atom, and Xputty::UTF8.

Referenced by os_widget_event_loop().

◆ strdecode()

void strdecode ( char *  target,
const char *  needle,
const char *  replacement 
)

strdecode - replace string in char*

Parameters
*target- the string to modify
*needle- the string to replace
*replacement- the replacement for the needle

Definition at line 432 of file xwidget-linux.c.

432 {
433 char buffer[1024] = { 0 };
434 char *insert_point = &buffer[0];
435 const char *tmp = target;
436 size_t needle_len = strlen(needle);
437 size_t repl_len = strlen(replacement);
438
439 while (1) {
440 const char *p = strstr(tmp, needle);
441 if (p == NULL) {
442 strcpy(insert_point, tmp);
443 break;
444 }
445 memcpy(insert_point, tmp, p - tmp);
446 insert_point += p - tmp;
447 memcpy(insert_point, replacement, repl_len);
448 insert_point += repl_len;
449 tmp = p + needle_len;
450 }
451 strcpy(target, buffer);
452}

Referenced by handle_drag_data().

◆ strremove()

void strremove ( char *  str,
const char *  sub 
)

Definition at line 419 of file xwidget-linux.c.

419 {
420 char *p, *q, *r;
421 if ((q = r = strstr(str, sub)) != NULL) {
422 size_t len = strlen(sub);
423 while ((r = strstr(p = r + len, sub)) != NULL) {
424 while (p < r)
425 *q++ = *p++;
426 }
427 while ((*q++ = *p++) != '\0')
428 continue;
429 }
430}

Referenced by handle_drag_data().

◆ utf8_from_locale()

char * utf8_from_locale ( char *  localestr)

utf8_from_locale - convert active codepage to utf8 must be freed by the caller

Parameters
*localestr- Pointer to char to convert
Returns
*char - the converted char in utf8 format

Definition at line 41 of file xwidget-linux.c.

41 {
42 char *s_to = NULL;
43 asprintf(&s_to, "%s",localestr);
44 return s_to;
45}

◆ widget_set_dnd_aware()

void widget_set_dnd_aware ( Widget_t w)

widget_set_dnd_aware - allow drag and drop for on Widget_t

Parameters
w- the Widget_t to send the event to

Definition at line 409 of file xwidget-linux.c.

409 {
410 Atom dnd_version = 5;
411 XChangeProperty (w->app->dpy, w->widget, w->app->XdndAware, XA_ATOM,
412 32, PropModeReplace, (unsigned char*)&dnd_version, 1);
413}

References Widget_t::app, Xputty::dpy, Widget_t::widget, and Xputty::XdndAware.

◆ widget_set_dnd_unaware()

void widget_set_dnd_unaware ( Widget_t w)

widget_set_dnd_unaware - disable drag and drop for on Widget_t

Parameters
w- the Widget_t to send the event to

Definition at line 415 of file xwidget-linux.c.

415 {
416 XDeleteProperty(w->app->dpy, w->widget, w->app->XdndAware);
417}

References Widget_t::app, Xputty::dpy, Widget_t::widget, and Xputty::XdndAware.

Variable Documentation

◆ default_error_handler

int(* default_error_handler) (Display *dpy, XErrorEvent *e) ( Display dpy,
XErrorEvent *  e 
)

Definition at line 34 of file xwidget-linux.c.

Referenced by os_send_systray_message().