Introduction
Introduction Statistics Contact Development Disclaimer Help
window.h - ledit - Text editor (WIP)
git clone git://lumidify.org/ledit.git (fast, but not encrypted)
git clone https://lumidify.org/ledit.git (encrypted, but very slow)
git clone git://4kcetb7mo7hj6grozzybxtotsub5bempzo4lirzc3437amof2c2impyd.onion/…
Log
Files
Refs
README
LICENSE
---
window.h (9546B)
---
1 #ifndef _WINDOW_H_
2 #define _WINDOW_H_
3
4 /*
5 * A window is associated with exactly one view and is responsible every…
6 * other than the actual text handling (of the text in the buffer).
7 * It's a bit ugly right now because the line editor for commands is imp…
8 * partially here and partially in keys_command, but that's the way it i…
9 */
10
11 #include <time.h>
12 #include <stdarg.h>
13 #include <X11/Xlib.h>
14 #include <X11/Xatom.h>
15 #include <X11/Xutil.h>
16 #include <X11/extensions/Xdbe.h>
17 #include <pango/pangoxft.h>
18
19 #include "common.h"
20 #include "clipboard.h"
21 #include "txtbuf.h"
22
23 typedef struct bottom_bar bottom_bar;
24
25 typedef struct {
26 /* Pango stuff */
27 /* FIXME: maybe move to common? */
28 PangoFontMap *fontmap;
29 PangoContext *context;
30 PangoFontDescription *font;
31
32 /* X stuff */
33 GC gc;
34 Window xwin;
35 XdbeBackBuffer back_buf; /* the back buffer for double buffering…
36 Drawable drawable; /* the actual drawable to draw to */
37 /* this is currently always the same as…
38 but that might be changed at some po…
39 XSetWindowAttributes wattrs;
40 Atom wm_delete_msg; /* used to check when window is closed …
41
42 int w; /* width of window */
43 int h; /* height of window */
44 int text_w; /* width of the text part of the window…
45 int text_h; /* height of the text part of the windo…
46 int scroll_dragging; /* whether scrollbar is being dragged w…
47 int scroll_grab_handle; /* the y position where the mouse was w…
48 long scroll_max; /* total pixel height of displayed text…
49 double scroll_offset; /* double for smoother scrolling */
50 int bottom_text_shown; /* whether editable text is shown at th…
51 int message_shown; /* whether a readonly message is shown …
52 bottom_bar *bb; /* encapsulates the text at the bottom …
53 int redraw; /* whether something has changed and th…
54 Cursor cursor_text; /* text cursor shown when cursor is ove…
55
56 /* stuff for filtering events so not too many have to be handled…
57 struct timespec last_scroll;
58 struct timespec last_motion;
59 struct timespec last_resize;
60 XEvent last_scroll_event;
61 XEvent last_motion_event;
62 XEvent last_resize_event;
63 int last_scroll_valid;
64 int last_motion_valid;
65 int last_resize_valid;
66 /* This is a hack to make the first resizing of the window go qu…
67 of being delayed due to the event filtering - this is noticea…
68 window managers that resize the window immediately after it i…
69 The whole event filtering system needs to be rethought anyway…
70 at least sort of works for the time being. (FIXME) */
71 int first_resize;
72 int scroll_num;
73 int scroll_delta;
74
75 /* IME stuff */
76 XIM xim;
77 XIC xic;
78 XPoint spot;
79 XVaNestedList spotlist;
80
81 ledit_common *common; /* shared with others */
82 ledit_clipboard *clipboard; /* also shared */
83
84 /* various callbacks */
85 void (*scroll_callback)(void *, long);
86 void (*button_callback)(void *, XEvent *);
87 void (*resize_callback)(void *);
88 void *scroll_cb_data;
89 void *button_cb_data;
90 void *resize_cb_data;
91 } ledit_window;
92
93 /*
94 * Create a window with initial mode 'mode'.
95 */
96 ledit_window *window_create(ledit_common *common, ledit_clipboard *clipb…
97
98 /*
99 * Destroy a window.
100 */
101 void window_destroy(ledit_window *window);
102
103 /* FIXME: this is a bit confusing because there's a difference between e…
104 text shown and non-editable message shown */
105
106 /*
107 * Move the cursor of the editable text at the bottom movement cursor po…
108 * Negative movement means to the left, positive movement to the right.
109 */
110 void window_move_bottom_bar_cursor(ledit_window *window, int movement);
111
112 /*
113 * Delete a unicode character from he editable text.
114 * Negative dir means to the left of the cursor, positive to the right.
115 */
116 void window_delete_bottom_bar_char(ledit_window *window, int dir);
117
118 /*
119 * Move the cursor of the editable text to position 0.
120 */
121 void window_bottom_bar_cursor_to_beginning(ledit_window *window);
122
123 /*
124 * Move the cursor of the editable text to the end of the line.
125 */
126 void window_bottom_bar_cursor_to_end(ledit_window *window);
127
128 /*
129 * Set the minimum byte position of the cursor of the editable text to '…
130 * This means that the cursor will not be allowed to go further left
131 * than that position (used e.g. for the ':' in commands).
132 */
133 void window_set_bottom_bar_min_pos(ledit_window *window, int pos);
134
135 /*
136 * Get the mininum position (see above).
137 */
138 int window_get_bottom_bar_min_pos(ledit_window *window);
139
140 /*
141 * Set whether the editable text is shown.
142 */
143 void window_set_bottom_bar_text_shown(ledit_window *window, int shown);
144
145 /*
146 * get whether the editable text is shown.
147 */
148 int ledit_window_bottom_bar_text_shown(ledit_window *window);
149
150 /*
151 * Set the byte position of the editable text cursor to 'byte_pos'.
152 */
153 void window_set_bottom_bar_cursor(ledit_window *window, int byte_pos);
154
155 /*
156 * Get the byte position of the editable text cursor.
157 */
158 int ledit_window_get_bottom_bar_cursor(ledit_window *window);
159
160 /*
161 * Insert 'len' bytes of text into the editable line at the cursor posit…
162 */
163 void window_insert_bottom_bar_text(ledit_window *window, char *text, int…
164
165 /*
166 * Set the text of the editable line.
167 */
168 void window_set_bottom_bar_text(ledit_window *window, char *text, int le…
169
170 /*
171 * Set the text after the minimum position.
172 * If the set minimum position is after the current length
173 * of the text in the bar, the text is just appended.
174 */
175 void window_set_bottom_bar_realtext(ledit_window *window, char *text, in…
176
177 /*
178 * Get the text of the editable line.
179 * WARNING: this is a direct pointer to the internal storage,
180 * it is not copied.
181 */
182 char *window_get_bottom_bar_text(ledit_window *window);
183
184 /*
185 * Show a non-editable message at the bottom.
186 */
187 void window_show_message(ledit_window *window, char *text, int len);
188
189 /*
190 * Show a non-editable message that is given as a
191 * format string and arguments as interpreted by
192 * vsnprintf(3)
193 * WARNING: This may reallocate the internal text storage for the
194 * bottom bar before actually using the format arguments, so don't
195 * ever pass parts of the text returned by window_get_bottom_bar_text
196 * to this function without first copying it.
197 */
198 void window_show_message_fmt(ledit_window *window, char *fmt, ...);
199
200 /*
201 * Hide the non-editable message.
202 */
203 void window_hide_message(ledit_window *window);
204
205 /*
206 * Get whether a non-editable message is shown.
207 */
208 int window_message_shown(ledit_window *window);
209
210 /* FIXME: document */
211 void window_set_format_args(ledit_window *window, ledit_mode mode, int h…
212
213 /*
214 * Set the total pixel height of the text.
215 */
216 void window_set_scroll_max(ledit_window *window, long max);
217
218 /*
219 * Set the scroll position of the window.
220 * This is in absolute pixels from the top of the text.
221 */
222 void window_set_scroll_pos(ledit_window *window, long pos);
223
224 /*
225 * Set a callback that will be called when the user scrolls.
226 * The callback is called with 'data' as the first argument and
227 * the scroll offset as the second argument.
228 */
229 void window_set_scroll_callback(ledit_window *window, void (*cb)(void *,…
230
231 /*
232 * Set a callback that is called when Button1 is clicked or released
233 * in the text area.
234 */
235 void window_set_button_callback(ledit_window *window, void (*cb)(void *,…
236
237 /*
238 * Set a callback that is called when the window is resized.
239 */
240 void window_set_resize_callback(ledit_window *window, void (*cb)(void *)…
241
242 /*
243 * The following three functions are used to register events that
244 * need to be filtered in order to avoid processing too many events
245 * (which leads to lagging).
246 */
247 void window_register_resize(ledit_window *window, XEvent *event);
248 void window_register_button_press(ledit_window *window, XEvent *event);
249 void window_register_motion(ledit_window *window, XEvent *event);
250
251 /*
252 * Check if any of the previously registered events should be handled
253 * now. This should be called every frame to check if processin is
254 * necessary.
255 */
256 void window_handle_filtered_events(ledit_window *window);
257
258 /*
259 * Clear the window.
260 */
261 void window_clear(ledit_window *window);
262
263 /*
264 * Redraw the window.
265 * This only redraws the parts mANAGED BY THE window.
266 * The text area needs to be redrawn separately.
267 */
268 void window_redraw(ledit_window *window);
269
270 /*
271 * Resize the window and call the resize callback if set.
272 */
273 void window_resize(ledit_window *window, int w, int h);
274
275 /*
276 * Get the size of the actual text area (everything other than the
277 * scrollbar and the line at the bottom).
278 */
279 void window_get_textview_size(ledit_window *window, int *w_ret, int *h_r…
280
281 /*
282 * Handle a button press.
283 * This does not filter events like the register function!
284 */
285 void window_button_press(ledit_window *window, XEvent *event, int scroll…
286
287 /*
288 * Handle a button release.
289 */
290 void window_button_release(ledit_window *window, XEvent *event);
291
292 /*
293 * Handle a button motion event.
294 * This does not filter events like the register function!
295 */
296 void window_drag_motion(ledit_window *window, XEvent *event);
297
298 /*
299 * Set the pixel position of the input method context.
300 * This is used by some input method editors to show an editor at
301 * the position that text is being inserted at.
302 */
303 void xximspot(ledit_window *window, int x, int y);
304
305 #endif
You are viewing proxied material from lumidify.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.