libxputty 0.1
Loading...
Searching...
No Matches
xwidget.h
Go to the documentation of this file.
1/*
2 * 0BSD
3 *
4 * BSD Zero Clause License
5 *
6 * Copyright (c) 2019 Hermann Meyer
7 *
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted.
10
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 *
19 */
20
28#pragma once
29
30#ifndef XWIDGET_H
31#define XWIDGET_H
32
33#include "xputty.h"
34#include "xwidget-platform.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*---------------------------------------------------------------------
41-----------------------------------------------------------------------
42 basic X11 widgets
43-----------------------------------------------------------------------
44----------------------------------------------------------------------*/
45
46#define SYSTEM_TRAY_REQUEST_DOCK 0
47#define SYSTEM_TRAY_BEGIN_MESSAGE 1
48#define SYSTEM_TRAY_CANCEL_MESSAGE 2
49
58typedef void (*vfunc)(void * widget, void * event, Xputty *main, void* user_data);
59
67typedef void (*evfunc)(void * widget, void * event, void* user_data);
68
69
76typedef void (*xevfunc)(void * widget, void* user_data);
77
107
150
235
242#define XPUTTY_WIDGET_NAME_COUNT 38
243#define XPUTTY_WIDGET_NAME_MAXLEN 256
244static const char widget_type_names[XPUTTY_WIDGET_NAME_COUNT + 1][XPUTTY_WIDGET_NAME_MAXLEN] = {
245 "WT_NONE",
246 "WT_WINDOW",
247 "WT_WIDGET",
248 "WT_BUTTON",
249 "WT_ON_OFF_BUTTON",
250 "WT_TOGGLE_BUTTON",
251 "WT_IMAGE_TOGGLE_BUTTON",
252 "WT_SWITCH_IMAGE_TOGGLE_BUTTON",
253 "WT_CHECK_BUTTON",
254 "WT_CHECK_BOX",
255 "WT_COMBOBOX",
256 "WT_FILE_DIALOG",
257 "WT_KNOB",
258 "WT_IMAGE_KNOB",
259 "WT_LABEL",
260 "WT_LISTBOX_VIEWPORT",
261 "WT_LISTBOX",
262 "WT_LISTBOX_ENTRY",
263 "WT_LISTVIEW_VIEWPORT",
264 "WT_LISTVIEW",
265 "WT_MENU",
266 "WT_MENU_VIEWPORT",
267 "WT_MENU_ITEM",
268 "WT_MENU_CHECK_ITEM",
269 "WT_MENU_RADIO_ITEM",
270 "WT_MESSAGE_DIALOG",
271 "WT_VMETER",
272 "WT_VMETER_SCALE",
273 "WT_HMETER",
274 "WT_HMETER_SCALE",
275 "WT_MIDI_KEYBOARD",
276 "WT_PLAYHEAD",
277 "WT_VSLIDER",
278 "WT_HSLIDER",
279 "WT_TOOLTIP",
280 "WT_TUNER",
281 "WT_VALUEDISPLAY",
282 "WT_TEXT_ENTRY",
283 "UNKNOWN"
284};
285
330
371
386enum {
388 IS_WIDGET = 1<<0,
390 IS_WINDOW = 1<<1,
392 IS_POPUP = 1<<2,
394 IS_RADIO = 1<<3,
400 HAS_FOCUS = 1<<6,
406 HAS_MEM = 1<<9,
410 FAST_REDRAW = 1<<11,
414 REUSE_IMAGE = 1<<13,
418 IS_SUBMENU = 1<<15,
421
422};
423
457struct Widget_t {
459 char input_label[32];
461 long long flags;
463 const char* label;
471 void *parent;
483 cairo_surface_t *surface;
485 cairo_t *cr;
487 cairo_surface_t *buffer;
489 cairo_t *crb;
491 cairo_surface_t *image;
504#ifdef __linux__
507#endif
509 int data;
511 int state;
513 int pos_x;
515 int pos_y;
517 int x;
519 int y;
521 int width;
526#ifdef _WIN32 //Widget_t extensions
528 bool mouse_inside;
531#endif //_WIN32 //Widget_t extensions
533 xevfunc xpaste_callback;
534};
535
536
550 int x, int y, int width, int height);
551
564 int x, int y, int width, int height);
565
573void connect_func(void (**event)(), void (*handler)());
574
581void widget_set_title(Widget_t *w, const char *title);
582
588void widget_show(Widget_t *w);
589
596
603
609void widget_hide(Widget_t *w);
610
617
624
631void show_tooltip(Widget_t *wid);
632
639void hide_tooltip(Widget_t *wid);
640
647
653void quit(Widget_t *w);
654
660void quit_widget(Widget_t *w);
661
671void transparent_draw(void * wid, void* user_data);
672
679void widget_draw(void * w_, void* user_data);
680
686void resize_childs(Widget_t *wid);
687
695
703
713void destroy_widget(Widget_t *w, Xputty *main);
714
724void widget_event_loop(void *w_, void* event, Xputty *main, void* user_data);
725
734void send_configure_event(Widget_t *w,int x, int y, int width, int height);
735
743
751
759
765void expose_widget(Widget_t *w);
766
774int key_mapping(Display *dpy, XKeyEvent *xkey);
775
782const char *widget_type_name(Widget_t *w);
783
791void strdecode(char *target, const char *needle, const char *replacement);
792
799
806
813void handle_drag_data(Widget_t *w, XEvent* event);
814
821void handle_dnd_enter(Xputty *main, XEvent* event);
822
830
837void send_dnd_status_event(Widget_t *w, XEvent* event);
838
846void copy_to_clipboard(Widget_t *w, char* text, int size);
847
854void send_to_clipboard(Widget_t *w, XEvent* event);
855
856
862int have_paste(Widget_t *w);
863
870
878
879#ifdef __cplusplus
880}
881#endif
882
883#endif //XWIDGET_H
Adjustment_t - struct to hold a controller adjustment.
Definition xadjustment.h:82
Childlist_t - struct to hold a Widget_t child list Xputty main holds a list of any Widget_t created...
Definition xchildlist.h:49
Func_t - struct to hold all supported event callbacks.
Definition xwidget.h:84
xevfunc configure_notify_callback
Definition xwidget.h:93
evfunc button_release_callback
Definition xwidget.h:101
xevfunc configure_callback
Definition xwidget.h:86
xevfunc map_notify_callback
Definition xwidget.h:94
xevfunc unmap_notify_callback
Definition xwidget.h:95
xevfunc expose_callback
Definition xwidget.h:85
evfunc key_release_callback
Definition xwidget.h:105
evfunc key_press_callback
Definition xwidget.h:104
xevfunc visibiliy_change_callback
Definition xwidget.h:98
evfunc double_click_callback
Definition xwidget.h:102
xevfunc leave_callback
Definition xwidget.h:88
xevfunc adj_callback
Definition xwidget.h:89
xevfunc value_changed_callback
Definition xwidget.h:90
xevfunc dnd_notify_callback
Definition xwidget.h:97
xevfunc user_callback
Definition xwidget.h:91
xevfunc mem_free_callback
Definition xwidget.h:92
evfunc motion_callback
Definition xwidget.h:103
xevfunc enter_callback
Definition xwidget.h:87
evfunc button_press_callback
Definition xwidget.h:100
xevfunc dialog_callback
Definition xwidget.h:96
Metrics_t - struct to receive window size, position & visibility Pass this struct to os_get_window_...
Resize_t - struct used to resize child widgets.
Definition xwidget.h:345
int init_height
Definition xwidget.h:355
float scale_y
Definition xwidget.h:359
float ascale
Definition xwidget.h:369
float cscale_y
Definition xwidget.h:363
Gravity gravity
Definition xwidget.h:347
float rcscale_x
Definition xwidget.h:365
float cscale_x
Definition xwidget.h:361
int init_width
Definition xwidget.h:353
int init_y
Definition xwidget.h:351
int init_x
Definition xwidget.h:349
float rcscale_y
Definition xwidget.h:367
float scale_x
Definition xwidget.h:357
Widget_t - struct to hold the basic Widget_t info.
Definition xwidget.h:457
int y
Definition xwidget.h:519
Resize_t scale
Definition xwidget.h:525
Adjustment_t * adj_y
Definition xwidget.h:495
XIM xim
Definition xwidget.h:503
vfunc event_callback
Definition xwidget.h:479
Adjustment_t * adj_x
Definition xwidget.h:493
int width
Definition xwidget.h:521
WidgetType widget_type
Definition xwidget.h:477
XColor_t * color_scheme
Definition xwidget.h:467
cairo_surface_t * image
Definition xwidget.h:491
Adjustment_t * adj
Definition xwidget.h:497
void * parent
Definition xwidget.h:471
int x
Definition xwidget.h:517
Window widget
Definition xwidget.h:469
int pos_y
Definition xwidget.h:515
cairo_surface_t * surface
Definition xwidget.h:483
cairo_surface_t * buffer
Definition xwidget.h:487
Metrics_t metrics_min
Definition xwidget.h:530
cairo_t * crb
Definition xwidget.h:489
int state
Definition xwidget.h:511
Childlist_t * childlist
Definition xwidget.h:499
int pos_x
Definition xwidget.h:513
int data
Definition xwidget.h:509
long long flags
Definition xwidget.h:461
char input_label[32]
Definition xwidget.h:459
void * private_struct
Definition xwidget.h:475
const char * label
Definition xwidget.h:463
Time double_click
Definition xwidget.h:506
cairo_t * cr
Definition xwidget.h:485
void * parent_struct
Definition xwidget.h:473
int height
Definition xwidget.h:523
XIC xic
Definition xwidget.h:501
Func_t func
Definition xwidget.h:481
Xputty * app
Definition xwidget.h:465
XColor_t - the Widget_t Color struct XColor_t could be used for theming you Widget_t set.
Definition xcolor.h:105
Xputty - the main struct. It should be declared before any other call to a Xputty function....
Definition xputty.h:228
void * XIM
void * XIC
XID Display
HWND Window
This file contains definitions and structs used on all platforms. Platform specific definitions are l...
Platform wrapper functions (Linux, MSWindows): This file contains forward definitions and structs for...
void widget_set_title(Widget_t *w, const char *title)
widget_set_title - set window title for a Widget_t
Definition xwidget.c:359
void strdecode(char *target, const char *needle, const char *replacement)
strdecode - replace string in char*
void widget_set_scale(Widget_t *w)
widget_set_scale - set scaling mode to scale a image surface to the size of the Widget_t surface
Definition xwidget.c:159
Widget_t * create_widget(Xputty *app, Widget_t *win, int x, int y, int width, int height)
*create_widget - create a widget A Widget_t could only be created as child of a other Widget_t To...
Definition xwidget.c:265
int key_mapping(Display *dpy, XKeyEvent *xkey)
_key_mapping - modifier key's mapped to a integer value
Definition xwidget.c:37
void expose_widget(Widget_t *w)
expose_widgets - send a expose event (EXPOSE) to a Widget_t
Definition xwidget.c:445
void receive_paste_from_clipboard(Widget_t *w, XEvent *event)
receive_paste_from_clipboard - receive textbuffer from clipboard
void quit_widget(Widget_t *w)
quit_widget - remove a widget from the processing loop
Definition xwidget.c:530
EventType
EventType - enum to hold identifier for all supported event callbacks Events could be connected to ...
Definition xwidget.h:131
@ UNMAP_NOTIFY
Definition xwidget.h:142
@ MAP_NOTIFY
Definition xwidget.h:141
@ POINTER_MOTION
Definition xwidget.h:146
@ KEY_PRESS
Definition xwidget.h:147
@ CONFIGURE_NOTIFY
Definition xwidget.h:140
@ CONFIGURE
Definition xwidget.h:133
@ KEY_RELEASE
Definition xwidget.h:148
@ VALUE_CHANGED
Definition xwidget.h:137
@ ADJ_INTERN
Definition xwidget.h:136
@ ENTER
Definition xwidget.h:134
@ MEM_FREE_CB
Definition xwidget.h:139
@ EXPOSE
Definition xwidget.h:132
@ LEAVE
Definition xwidget.h:135
@ USER
Definition xwidget.h:138
@ BUTTON_RELEASE
Definition xwidget.h:145
@ BUTTON_PRESS
Definition xwidget.h:144
@ DIALOG_RESPONSE
Definition xwidget.h:143
void send_button_release_event(Widget_t *w)
send_button_release_event - send ButtonRelease event to Widget_t simulate a BUTTON_RELEASE Event
Definition xwidget.c:518
Widget_t * create_window(Xputty *app, Window win, int x, int y, int width, int height)
*create_window - create a Window You need to create as least minimun one Window to get started....
Definition xwidget.c:163
Widget_t * get_toplevel_widget(Xputty *main)
*get_toplevel_widget - get pointer to the top level Widget_t
Definition xwidget.c:441
void connect_func(void(**event)(), void(*handler)())
connect_func - connect a event with a handler without type check. For supported events see: Func_t
Definition xwidget.c:352
void resize_childs(Widget_t *wid)
resize_childs - intern check if child widgets needs resizing
Definition xwidget.c:151
void widget_event_loop(void *w_, void *event, Xputty *main, void *user_data)
widget_event_loop - the internal widget event loop
Definition xwidget.c:506
void quit(Widget_t *w)
quit - exit the main loop
Definition xwidget.c:526
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
void widget_draw(void *w_, void *user_data)
widget_draw - redraw only the widget,not the child widgets
Definition xwidget.c:479
void submenu_widget_show_all(Widget_t *w)
submenu_widget_show_all - map/show submenu Widget_t with all childs
Definition xwidget.c:410
Gravity
Gravity - enum to indicate how to resize a widget.
Definition xwidget.h:298
@ SOUTHEAST
Definition xwidget.h:306
@ CENTER
Definition xwidget.h:320
@ EASTSOUTH
Definition xwidget.h:314
@ WESTSOUTH
Definition xwidget.h:318
@ EASTWEST
Definition xwidget.h:310
@ SOUTHWEST
Definition xwidget.h:304
@ MENUITEM
Definition xwidget.h:326
@ SOUTHCENTER
Definition xwidget.h:308
@ ASPECT
Definition xwidget.h:322
@ FIXEDSIZE
Definition xwidget.h:324
@ NORTHEAST
Definition xwidget.h:302
@ NONE
Definition xwidget.h:328
@ NORTHWEST
Definition xwidget.h:300
@ WESTNORTH
Definition xwidget.h:316
@ EASTNORTH
Definition xwidget.h:312
@ IS_TOOLTIP
Definition xwidget.h:396
@ IS_WIDGET
Definition xwidget.h:388
@ HIDE_ON_DELETE
Definition xwidget.h:412
@ FAST_REDRAW
Definition xwidget.h:410
@ HAS_POINTER
Definition xwidget.h:402
@ NO_AUTOREPEAT
Definition xwidget.h:408
@ USE_TRANSPARENCY
Definition xwidget.h:398
@ HAS_MEM
Definition xwidget.h:406
@ HAS_TOOLTIP
Definition xwidget.h:404
@ IS_RADIO
Definition xwidget.h:394
@ HAS_FOCUS
Definition xwidget.h:400
@ NO_PROPAGATE
Definition xwidget.h:416
@ IS_WINDOW
Definition xwidget.h:390
@ DONT_PROPAGATE
Definition xwidget.h:420
@ REUSE_IMAGE
Definition xwidget.h:414
@ IS_POPUP
Definition xwidget.h:392
@ IS_SUBMENU
Definition xwidget.h:418
void(* vfunc)(void *widget, void *event, Xputty *main, void *user_data)
*vfunc - function pointer to connect Xevents from the main loop to Widget_t
Definition xwidget.h:58
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 send_to_clipboard(Widget_t *w, XEvent *event)
send_to_clipboard - send textbuffer to clipboard on request
void send_dnd_finished_event(Widget_t *w, XEvent *event)
send_dnd_finished_event - notify the drag sender that the event is handled
void send_configure_event(Widget_t *w, int x, int y, int width, int height)
send_configure_event - send a ConfigureNotify to Widget_t used to resize a Widget_t
Definition xwidget.c:510
void widget_show(Widget_t *w)
widget_show - map/show widget
Definition xwidget.c:363
void widget_reset_scale(Widget_t *w)
widget_reset_scale - used to reset scaling mode after a image surface is drawn to the Widget_t surfac...
Definition xwidget.c:155
WidgetType
WidgetType - enum describing the kind of the widget (button, menu, ...) The widget_type member can ...
Definition xwidget.h:195
@ WT_LISTBOX
Definition xwidget.h:212
@ WT_LABEL
Definition xwidget.h:210
@ WT_LISTVIEW_VIEWPORT
Definition xwidget.h:214
@ WT_IMAGE_TOGGLE_BUTTON
Definition xwidget.h:202
@ WT_LISTBOX_ENTRY
Definition xwidget.h:213
@ WT_LISTVIEW
Definition xwidget.h:215
@ WT_NONE
Definition xwidget.h:196
@ WT_VALUEDISPLAY
Definition xwidget.h:232
@ WT_TOOLTIP
Definition xwidget.h:230
@ WT_WINDOW
Definition xwidget.h:197
@ WT_SWITCH_IMAGE_TOGGLE_BUTTON
Definition xwidget.h:203
@ WT_COMBOBOX
Definition xwidget.h:206
@ WT_TUNER
Definition xwidget.h:231
@ WT_HSLIDER
Definition xwidget.h:229
@ WT_MESSAGE_DIALOG
Definition xwidget.h:221
@ WT_VMETER
Definition xwidget.h:222
@ WT_CHECK_BOX
Definition xwidget.h:205
@ WT_ON_OFF_BUTTON
Definition xwidget.h:200
@ WT_PLAYHEAD
Definition xwidget.h:227
@ WT_MIDI_KEYBOARD
Definition xwidget.h:226
@ WT_VSLIDER
Definition xwidget.h:228
@ WT_CHECK_BUTTON
Definition xwidget.h:204
@ WT_MENU_VIEWPORT
Definition xwidget.h:217
@ WT_HMETER
Definition xwidget.h:224
@ WT_BUTTON
Definition xwidget.h:199
@ WT_KNOB
Definition xwidget.h:208
@ WT_MENU_RADIO_ITEM
Definition xwidget.h:220
@ WT_MENU_CHECK_ITEM
Definition xwidget.h:219
@ WT_TEXT_ENTRY
Definition xwidget.h:233
@ WT_MENU_ITEM
Definition xwidget.h:218
@ WT_HMETER_SCALE
Definition xwidget.h:225
@ WT_WIDGET
Definition xwidget.h:198
@ WT_VMETER_SCALE
Definition xwidget.h:223
@ WT_LISTBOX_VIEWPORT
Definition xwidget.h:211
@ WT_TOGGLE_BUTTON
Definition xwidget.h:201
@ WT_IMAGE_KNOB
Definition xwidget.h:209
@ WT_FILE_DIALOG
Definition xwidget.h:207
@ WT_MENU
Definition xwidget.h:216
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 widget_set_dnd_unaware(Widget_t *w)
widget_set_dnd_unaware - disable drag and drop for on Widget_t
void(* xevfunc)(void *widget, void *user_data)
*xevfunc - function pointer to connect XEvents from a Widget_t to a event handler
Definition xwidget.h:76
void widget_show_all(Widget_t *w)
widget_show_all - map/show Widget_t with all childs
Definition xwidget.c:386
void handle_dnd_enter(Xputty *main, XEvent *event)
handle_drag_enter - handle drag event enter the Widget_t
const char * widget_type_name(Widget_t *w)
widget_type_name - textual representation of (Widget_t*)->widget_type
Definition xwidget.c:27
void widget_hide(Widget_t *w)
widget_hide - unmap/hide a Widget_t
Definition xwidget.c:368
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
void(* evfunc)(void *widget, void *event, void *user_data)
*evfunc - function pointer to connect Xevents from a Widget_t to a event handler
Definition xwidget.h:67
void send_systray_message(Widget_t *w)
send_systray_message - request a systray icon for Widget_t currently not working
Definition xwidget.c:522
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
void handle_drag_data(Widget_t *w, XEvent *event)
handle_drag_data - handle recived drag data
void send_button_press_event(Widget_t *w)
send_button_press_event - send ButtonPress event to Widget_t simulate a BUTTON_PRESS Event
Definition xwidget.c:514
void copy_to_clipboard(Widget_t *w, char *text, int size)
copy_to_clipboard - send textbuffer to clipboard
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 widget_hide_all(Widget_t *w)
widget_hide_all - unmap/hide all Widget_t from app
Definition xwidget.c:377
void pop_widget_show_all(Widget_t *w)
pop_widget_show_all - map/show popup widget with all it's childs
Definition xwidget.c:400
void widget_set_dnd_aware(Widget_t *w)
widget_set_dnd_aware - allow drag and drop for on Widget_t