ltk.h - ltkx - GUI toolkit for X11 (old)
HTML git clone git://lumidify.org/ltkx.git (fast, but not encrypted)
HTML git clone https://lumidify.org/ltkx.git (encrypted, but very slow)
HTML git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/ltkx.git (over tor)
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
ltk.h (4635B)
---
1 /*
2 * This file is part of the Lumidify ToolKit (LTK)
3 * Copyright (c) 2016, 2017, 2018 lumidify <nobody@lumidify.org>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #ifndef _LTK_H_
25 #define _LTK_H_
26
27 /* Requires the following includes: <X11/Xlib.h>, <X11/Xutil.h> */
28
29 typedef struct {
30 int x;
31 int y;
32 int w;
33 int h;
34 } LtkRect;
35
36 typedef enum {
37 LTK_STICKY_LEFT = 1 << 0,
38 LTK_STICKY_RIGHT = 1 << 1,
39 LTK_STICKY_TOP = 1 << 2,
40 LTK_STICKY_BOTTOM = 1 << 3
41 } LtkStickyMask;
42
43 typedef enum {
44 LTK_NORMAL = 0,
45 LTK_HOVER = 1,
46 LTK_PRESSED = 2,
47 LTK_ACTIVE = 3,
48 LTK_HOVERACTIVE = 4,
49 LTK_DISABLED = 5
50 } LtkWidgetState;
51
52 typedef struct LtkWindow LtkWindow;
53
54 /* FIXME: change row, column, etc. to void* struct so
55 other layout systems can be implemented */
56 typedef struct LtkWidget {
57 LtkWindow *window;
58 struct LtkWidget *active_widget;
59 struct LtkWidget *hover_widget;
60 struct LtkWidget *parent;
61
62 void (*key_press) (void *, XEvent event);
63 void (*key_release) (void *, XEvent event);
64 void (*mouse_press) (void *, XEvent event);
65 void (*mouse_release) (void *, XEvent event);
66 void (*motion_notify) (void *, XEvent event);
67 void (*mouse_leave) (void *, XEvent event);
68 void (*mouse_enter) (void *, XEvent event);
69
70 void (*resize) (void *, int, int);
71 void (*draw) (void *);
72 void (*destroy) (void *);
73
74 LtkRect collision_rect; /* rect for collision with mouse */
75 LtkRect rect; /* rect in grid - this is only different when the widget is floating */
76 unsigned int row;
77 unsigned int column;
78 unsigned int row_span;
79 unsigned int column_span;
80 unsigned int needs_redraw;
81 LtkWidgetState state;
82 unsigned short sticky;
83 } LtkWidget;
84
85 typedef struct LtkWindow {
86 Window xwindow;
87 GC gc;
88 LtkWidget *root_widget;
89 int (*other_event) (LtkWindow *, XEvent event);
90 LtkRect rect;
91 LtkWidget **float_widgets;
92 int num_float_widgets;
93 int max_float_widgets;
94 } LtkWindow;
95
96 typedef struct LtkWindowTheme {
97 int border_width;
98 char *font;
99 XColor fg;
100 XColor bg;
101 } LtkWindowTheme;
102
103 typedef struct LtkButtonTheme LtkButtonTheme;
104
105 typedef struct {
106 LtkWindowTheme *window;
107 LtkButtonTheme *button;
108 } LtkTheme;
109
110 typedef struct LtkTextManager LtkTextManager;
111 LtkTextManager *ltk_get_text_manager(void);
112 LtkTheme *ltk_get_theme(void);
113 Display *ltk_get_display(void);
114 Colormap ltk_get_colormap(void);
115
116 LtkTheme *ltk_load_theme(const char *path);
117
118 typedef struct LtkTextManager LtkTextManager;
119
120 void ltk_window_invalidate_rect(LtkWindow *window, LtkRect rect);
121
122 void ltk_init(const char *theme_path);
123
124 void ltk_fatal(const char *msg);
125
126 XColor ltk_create_xcolor(const char *hex);
127
128 void ltk_mainloop(void);
129
130 LtkWindow *ltk_create_window(const char *title, int x, int y,
131 unsigned int w, unsigned int h);
132
133 void ltk_redraw_window(LtkWindow *window, LtkRect rect);
134
135 void ltk_remove_window(LtkWindow *window);
136
137 void ltk_destroy_window(LtkWindow *window);
138
139 void ltk_window_other_event(LtkWindow *window, XEvent event);
140
141 void ltk_destroy_theme(LtkTheme *theme);
142
143 int ltk_collide_rect(LtkRect rect, int x, int y);
144
145 char *ltk_read_file(const char *path, unsigned long *len);
146
147 void ltk_change_active_widget_state(void *widget, LtkWidgetState state);
148
149 void ltk_remove_active_widget(void *widget);
150
151 void ltk_remove_hover_widget(void *widget);
152
153 void ltk_fill_widget_defaults(LtkWidget *widget, LtkWindow * window,
154 void (*draw) (void *), void (*destroy) (void *), unsigned int needs_redraw);
155
156 void ltk_widget_mouse_press_event(void *widget, XEvent event);
157
158 void ltk_widget_mouse_release_event(void *widget, XEvent event);
159
160 void ltk_widget_motion_notify_event(void *widget, XEvent event);
161
162 void ltk_handle_event(XEvent event);
163
164 #endif