Révision | 0087b47de8bd97a570875315eb877ee3f9889ac7 (tree) |
---|---|
l'heure | 2023-02-20 21:37:51 |
Auteur | phabrics <phabrics@phab...> |
Commiter | phabrics |
More GTK3->GTK4 changes checkpoint.
@@ -227,10 +227,13 @@ _tme_keyboard_keyval_name(tme_keyboard_keyval_t keyval) | ||
227 | 227 | |
228 | 228 | /* this is a generic callback for a key press or release event: */ |
229 | 229 | int |
230 | -_tme_keyboard_key_press(int down, tme_keyboard_keyval_t key, void *disp) | |
230 | +_tme_keyboard_key_event(int down, tme_keyboard_keyval_t key, void *disp) | |
231 | 231 | { |
232 | 232 | struct tme_keyboard_event tme_event; |
233 | 233 | struct tme_display *display = (_tme_display_get) ? (_tme_display_get(disp)) : (disp); |
234 | + int was_empty; | |
235 | + int new_callouts; | |
236 | + int rc; | |
234 | 237 | |
235 | 238 | /* make a tme event from this key event: */ |
236 | 239 | tme_event.tme_keyboard_event_type |
@@ -243,16 +246,6 @@ _tme_keyboard_key_press(int down, tme_keyboard_keyval_t key, void *disp) | ||
243 | 246 | = key; |
244 | 247 | tme_event.tme_keyboard_event_time = tme_thread_get_time(); |
245 | 248 | |
246 | - return _tme_keyboard_key_event(&tme_event, display); | |
247 | -} | |
248 | - | |
249 | -int | |
250 | -_tme_keyboard_key_event(struct tme_keyboard_event *tme_event, struct tme_display *display) | |
251 | -{ | |
252 | - int was_empty; | |
253 | - int new_callouts; | |
254 | - int rc; | |
255 | - | |
256 | 249 | /* lock the mutex: */ |
257 | 250 | tme_mutex_lock(&display->tme_display_mutex); |
258 | 251 |
@@ -260,9 +253,9 @@ _tme_keyboard_key_event(struct tme_keyboard_event *tme_event, struct tme_display | ||
260 | 253 | new_callouts = 0; |
261 | 254 | |
262 | 255 | /* get any keycode associated with this keysym: */ |
263 | - tme_event->tme_keyboard_event_keycode | |
256 | + tme_event.tme_keyboard_event_keycode | |
264 | 257 | = tme_keyboard_hash_data_to_keyval(tme_hash_lookup(display->tme_display_keyboard_keysym_to_keycode, |
265 | - tme_keyboard_hash_data_from_keyval(tme_event->tme_keyboard_event_keyval))); | |
258 | + tme_keyboard_hash_data_from_keyval(tme_event.tme_keyboard_event_keyval))); | |
266 | 259 | |
267 | 260 | /* remember if the keyboard buffer was empty: */ |
268 | 261 | was_empty |
@@ -270,7 +263,7 @@ _tme_keyboard_key_event(struct tme_keyboard_event *tme_event, struct tme_display | ||
270 | 263 | |
271 | 264 | /* add this tme event to the keyboard buffer: */ |
272 | 265 | rc = tme_keyboard_buffer_copyin(display->tme_display_keyboard_buffer, |
273 | - tme_event); | |
266 | + &tme_event); | |
274 | 267 | assert (rc == TME_OK); |
275 | 268 | |
276 | 269 | /* if the keyboard buffer was empty and now it isn't, |
@@ -197,7 +197,7 @@ void _tme_screen_xlat_set _TME_P((struct tme_screen *screen)); | ||
197 | 197 | void _tme_keyboard_new _TME_P((struct tme_display *)); |
198 | 198 | int _tme_keyboard_connections_new _TME_P((struct tme_display *, |
199 | 199 | struct tme_connection **)); |
200 | -int _tme_keyboard_key_press _TME_P((int down, tme_keyboard_keyval_t key, void *disp)); | |
200 | +int _tme_keyboard_key_event _TME_P((int down, tme_keyboard_keyval_t key, void *disp)); | |
201 | 201 | void _tme_mouse_new _TME_P((struct tme_display *)); |
202 | 202 | void _tme_mouse_mode_off _TME_P((struct tme_screen *, tme_uint32_t)); |
203 | 203 | int _tme_mouse_connections_new _TME_P((struct tme_display *, |
@@ -60,7 +60,7 @@ static gboolean _tme_gtk_init(void) { | ||
60 | 60 | #endif |
61 | 61 | |
62 | 62 | static void |
63 | -_tme_gtk_display_bell(struct tme_gdk_display *display) { | |
63 | +_tme_gtk_display_bell(_tme_gtk_display *display) { | |
64 | 64 | gdk_display_beep(display->tme_gdk_display); |
65 | 65 | } |
66 | 66 |
@@ -78,7 +78,7 @@ _tme_gtk_display_update(struct tme_display *display) { | ||
78 | 78 | /* this sets the screen scaling to that indicated by the Scale menu: */ |
79 | 79 | static void |
80 | 80 | _tme_gtk_screen_scale_default(GtkWidget *widget, |
81 | - struct tme_gtk_screen *screen) | |
81 | + _tme_gtk_screen *screen) | |
82 | 82 | { |
83 | 83 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
84 | 84 | return; |
@@ -89,7 +89,7 @@ _tme_gtk_screen_scale_default(GtkWidget *widget, | ||
89 | 89 | /* this sets the screen scaling to that indicated by the Scale menu: */ |
90 | 90 | static void |
91 | 91 | _tme_gtk_screen_scale_half(GtkWidget *widget, |
92 | - struct tme_gtk_screen *screen) | |
92 | + _tme_gtk_screen *screen) | |
93 | 93 | { |
94 | 94 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
95 | 95 | return; |
@@ -100,7 +100,7 @@ _tme_gtk_screen_scale_half(GtkWidget *widget, | ||
100 | 100 | /* this sets the screen scaling to that indicated by the Scale menu: */ |
101 | 101 | static void |
102 | 102 | _tme_gtk_screen_scale_full(GtkWidget *widget, |
103 | - struct tme_gtk_screen *screen) | |
103 | + _tme_gtk_screen *screen) | |
104 | 104 | { |
105 | 105 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
106 | 106 | return; |
@@ -111,7 +111,7 @@ _tme_gtk_screen_scale_full(GtkWidget *widget, | ||
111 | 111 | /* this sets the screen scaling to that indicated by the Scale menu: */ |
112 | 112 | static void |
113 | 113 | _tme_gtk_screen_scale_double(GtkWidget *widget, |
114 | - struct tme_gtk_screen *screen) | |
114 | + _tme_gtk_screen *screen) | |
115 | 115 | { |
116 | 116 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
117 | 117 | return; |
@@ -122,7 +122,7 @@ _tme_gtk_screen_scale_double(GtkWidget *widget, | ||
122 | 122 | #if GTK_MAJOR_VERSION == 3 |
123 | 123 | /* this sets the screen size: */ |
124 | 124 | static inline void |
125 | -_tme_screen_format_set(struct tme_gtk_screen *screen, | |
125 | +_tme_screen_format_set(_tme_gtk_screen *screen, | |
126 | 126 | cairo_format_t format) |
127 | 127 | { |
128 | 128 | screen->tme_gtk_screen_format = format; |
@@ -132,7 +132,7 @@ _tme_screen_format_set(struct tme_gtk_screen *screen, | ||
132 | 132 | /* this sets the screen format to that indicated by the Format menu: */ |
133 | 133 | static void |
134 | 134 | _tme_gtk_screen_format_argb32(GtkWidget *widget, |
135 | - struct tme_gtk_screen *screen) | |
135 | + _tme_gtk_screen *screen) | |
136 | 136 | { |
137 | 137 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
138 | 138 | return; |
@@ -143,7 +143,7 @@ _tme_gtk_screen_format_argb32(GtkWidget *widget, | ||
143 | 143 | /* this sets the screen format to that indicated by the Format menu: */ |
144 | 144 | static void |
145 | 145 | _tme_gtk_screen_format_rgb24(GtkWidget *widget, |
146 | - struct tme_gtk_screen *screen) | |
146 | + _tme_gtk_screen *screen) | |
147 | 147 | { |
148 | 148 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
149 | 149 | return; |
@@ -154,7 +154,7 @@ _tme_gtk_screen_format_rgb24(GtkWidget *widget, | ||
154 | 154 | /* this sets the screen format to that indicated by the Format menu: */ |
155 | 155 | static void |
156 | 156 | _tme_gtk_screen_format_a8(GtkWidget *widget, |
157 | - struct tme_gtk_screen *screen) | |
157 | + _tme_gtk_screen *screen) | |
158 | 158 | { |
159 | 159 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
160 | 160 | return; |
@@ -165,7 +165,7 @@ _tme_gtk_screen_format_a8(GtkWidget *widget, | ||
165 | 165 | /* this sets the screen format to that indicated by the Format menu: */ |
166 | 166 | static void |
167 | 167 | _tme_gtk_screen_format_a1(GtkWidget *widget, |
168 | - struct tme_gtk_screen *screen) | |
168 | + _tme_gtk_screen *screen) | |
169 | 169 | { |
170 | 170 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
171 | 171 | return; |
@@ -176,7 +176,7 @@ _tme_gtk_screen_format_a1(GtkWidget *widget, | ||
176 | 176 | /* this sets the screen format to that indicated by the Format menu: */ |
177 | 177 | static void |
178 | 178 | _tme_gtk_screen_format_rgb16_565(GtkWidget *widget, |
179 | - struct tme_gtk_screen *screen) | |
179 | + _tme_gtk_screen *screen) | |
180 | 180 | { |
181 | 181 | if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(GTK_MENU_ITEM(widget)))) |
182 | 182 | return; |
@@ -204,7 +204,7 @@ static struct tme_display_menu_item scale_items[] = | ||
204 | 204 | }; |
205 | 205 | |
206 | 206 | /* Screen-specific size request */ |
207 | -static void _tme_gtk_screen_resize(struct tme_gtk_screen *screen) { | |
207 | +static void _tme_gtk_screen_resize(_tme_gtk_screen *screen) { | |
208 | 208 | struct tme_fb_connection *conn_fb = screen->screen.tme_screen_fb; |
209 | 209 | |
210 | 210 | /* set a minimum size */ |
@@ -224,14 +224,17 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
224 | 224 | #endif |
225 | 225 | gpointer _screen) |
226 | 226 | { |
227 | - struct tme_gtk_screen *screen; | |
227 | + _tme_gtk_screen *screen; | |
228 | 228 | struct tme_display *display; |
229 | 229 | struct tme_fb_connection *conn_fb; |
230 | -#if GTK_MAJOR_VERSION == 3 | |
231 | - GdkWindow *window; | |
230 | +#if GTK_MAJOR_VERSION == 4 | |
231 | + GdkSurface | |
232 | +#elif GTK_MAJOR_VERSION == 3 | |
233 | + GdkWindow | |
232 | 234 | #endif |
235 | + *window; | |
233 | 236 | |
234 | - screen = (struct tme_gtk_screen *) _screen; | |
237 | + screen = (_tme_gtk_screen *) _screen; | |
235 | 238 | |
236 | 239 | /* get the display: */ |
237 | 240 | display = screen->screen.tme_screen_display; |
@@ -245,15 +248,20 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
245 | 248 | } |
246 | 249 | |
247 | 250 | #if GTK_MAJOR_VERSION == 4 |
248 | - if (gtk_native_get_surface(gtk_widget_get_native(widget))) { | |
251 | + window = gtk_native_get_surface(gtk_widget_get_native(widget)); | |
252 | + | |
253 | + // screen->screen.tme_screen_scale = gdk_surface_get_scale_factor(window); | |
254 | + | |
255 | + if(window) { | |
249 | 256 | screen->tme_gtk_screen_surface = |
250 | - gdk_surface_create_similar_surface(gtk_native_get_surface(gtk_widget_get_native(widget)), | |
257 | + gdk_surface_create_similar_surface(window, | |
251 | 258 | CAIRO_CONTENT_COLOR, |
252 | - gtk_widget_get_width(widget), | |
253 | - gtk_widget_get_height(widget)); | |
259 | + gtk_widget_get_width(widget) /* * screen->screen.tme_screen_scale */, | |
260 | + gtk_widget_get_height(widget) // * screen->screen.tme_screen_scale | |
261 | + ); | |
254 | 262 | } |
255 | 263 | #elif GTK_MAJOR_VERSION == 3 |
256 | - window = gtk_widget_get_window(screen->tme_gtk_screen_gtkframe); | |
264 | + window = gtk_widget_get_window(widget); | |
257 | 265 | |
258 | 266 | screen->screen.tme_screen_scale = gdk_window_get_scale_factor(window); |
259 | 267 |
@@ -291,7 +299,7 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
291 | 299 | |
292 | 300 | /* this is called before the screen's display is updated: */ |
293 | 301 | static void |
294 | -_tme_gtk_screen_redraw(struct tme_gtk_screen *screen, int x, int y, int w, int h) | |
302 | +_tme_gtk_screen_redraw(_tme_gtk_screen *screen, int x, int y, int w, int h) | |
295 | 303 | { |
296 | 304 | cairo_surface_flush(screen->tme_gtk_screen_surface); |
297 | 305 | cairo_surface_mark_dirty(screen->tme_gtk_screen_surface); |
@@ -312,9 +320,9 @@ _tme_gtk_screen_draw(GtkWidget *widget, | ||
312 | 320 | gpointer _screen) |
313 | 321 | { |
314 | 322 | struct tme_display *display; |
315 | - struct tme_gtk_screen *screen; | |
323 | + _tme_gtk_screen *screen; | |
316 | 324 | |
317 | - screen = (struct tme_gtk_screen *) _screen; | |
325 | + screen = (_tme_gtk_screen *) _screen; | |
318 | 326 | |
319 | 327 | /* get the display: */ |
320 | 328 | display = screen->screen.tme_screen_display; |
@@ -331,18 +339,25 @@ _tme_gtk_screen_draw(GtkWidget *widget, | ||
331 | 339 | return FALSE; |
332 | 340 | } |
333 | 341 | |
342 | +static void | |
343 | +_tme_gtk_screen_close(_tme_gtk_screen *screen) | |
344 | +{ | |
345 | + if (screen->tme_gtk_screen_surface) | |
346 | + cairo_surface_destroy (screen->tme_gtk_screen_surface); | |
347 | +} | |
348 | + | |
334 | 349 | /* this makes a new screen: */ |
335 | -struct tme_gtk_screen * | |
336 | -_tme_gtk_screen_new(struct tme_gdk_display *display, | |
350 | +_tme_gtk_screen * | |
351 | +_tme_gtk_screen_new(_tme_gtk_display *display, | |
337 | 352 | struct tme_connection *conn) |
338 | 353 | { |
339 | - struct tme_gtk_screen *screen; | |
354 | + _tme_gtk_screen *screen; | |
340 | 355 | GtkWidget *menu_bar; |
341 | 356 | GtkWidget *menu; |
342 | 357 | GtkWidget *submenu; |
343 | 358 | GtkWidget *menu_item; |
344 | 359 | |
345 | - screen = tme_screen_new(display, struct tme_gtk_screen, conn); | |
360 | + screen = tme_screen_new(display, _tme_gtk_screen, conn); | |
346 | 361 | |
347 | 362 | /* create the top-level window, and allow it to shrink, grow, |
348 | 363 | and auto-shrink: */ |
@@ -384,7 +399,7 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
384 | 399 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); |
385 | 400 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item); |
386 | 401 | |
387 | -#if GTK_MAJOR_VERSION == 4 | |
402 | +#if GTK_MAJOR_VERSION == 3 | |
388 | 403 | /* create the Screen colormap submenu: */ |
389 | 404 | submenu = _tme_display_menu_radio(screen, format_items, TME_ARRAY_ELS(format_items)); |
390 | 405 |
@@ -393,6 +408,9 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
393 | 408 | // gtk_widget_show(menu_item); |
394 | 409 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); |
395 | 410 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item); |
411 | + | |
412 | + _tme_screen_format_set(screen, CAIRO_FORMAT_RGB24); | |
413 | + | |
396 | 414 | #endif |
397 | 415 | |
398 | 416 | /* create the Screen menu bar item, attach the menu to it, and |
@@ -410,19 +428,16 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
410 | 428 | // _tme_gtk_screen_init(screen->tme_gtk_screen_gtkframe, screen); |
411 | 429 | |
412 | 430 | |
413 | - _tme_screen_format_set(screen, CAIRO_FORMAT_RGB24); | |
414 | - | |
415 | 431 | /* pack the Gtkframe into the outer vertical packing box: */ |
416 | 432 | gtk_box_pack_start(GTK_BOX(screen->tme_gtk_screen_vbox0), |
417 | 433 | screen->tme_gtk_screen_gtkframe, |
418 | 434 | FALSE, FALSE, 0); |
419 | 435 | |
420 | 436 | #if GTK_MAJOR_VERSION == 4 |
421 | - gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (screen->tme_gtk_screen_gtkframe), | |
422 | - _tme_gtk_screen_draw, screen, NULL); | |
437 | + gtk_drawing_area_set_draw_func(GTK_DRAWING_AREA(screen->tme_gtk_screen_gtkframe), | |
438 | + _tme_gtk_screen_draw, screen, NULL); | |
423 | 439 | g_signal_connect_after(screen->tme_gtk_screen_gtkframe, "resize", |
424 | 440 | G_CALLBACK(_tme_gtk_screen_configure), screen); |
425 | - | |
426 | 441 | #elif GTK_MAJOR_VERSION == 3 |
427 | 442 | g_signal_connect(screen->tme_gtk_screen_gtkframe, "draw", |
428 | 443 | G_CALLBACK(_tme_gtk_screen_draw), screen); |
@@ -436,8 +451,12 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
436 | 451 | /* attach the keyboard to this screen: */ |
437 | 452 | _tme_gtk_keyboard_attach(screen); |
438 | 453 | |
439 | - gtk_window_set_title(GTK_WINDOW(screen->tme_gtk_screen_window), display->display.tme_display_title); | |
454 | + gtk_window_set_title(GTK_WINDOW(screen->tme_gtk_screen_window), | |
455 | + display->display.tme_display_title); | |
440 | 456 | |
457 | + g_signal_connect(screen->tme_gtk_screen_window, "destroy", | |
458 | + G_CALLBACK(_tme_gtk_screen_close), screen); | |
459 | + | |
441 | 460 | /* unlock our mutex: */ |
442 | 461 | tme_mutex_unlock(&display->display.tme_display_mutex); |
443 | 462 |
@@ -452,7 +471,7 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
452 | 471 | |
453 | 472 | /* this creates a menu of radio buttons: */ |
454 | 473 | GtkWidget * |
455 | -_tme_display_menu_radio(struct tme_gtk_screen *screen, | |
474 | +_tme_display_menu_radio(_tme_gtk_screen *screen, | |
456 | 475 | struct tme_display_menu_item menu_items[], |
457 | 476 | int num_items) |
458 | 477 | { |
@@ -484,25 +503,12 @@ _tme_display_menu_radio(struct tme_gtk_screen *screen, | ||
484 | 503 | return (menu); |
485 | 504 | } |
486 | 505 | |
487 | -/* this is a GTK callback for an enter notify event, that has the | |
488 | - widget grab focus and then continue normal event processing: */ | |
489 | -gint | |
490 | -_tme_display_enter_focus(GtkWidget *widget, | |
491 | - GdkEvent *gdk_event_raw, | |
492 | - gpointer junk) | |
493 | -{ | |
494 | - | |
495 | - /* grab the focus: */ | |
496 | - gtk_widget_grab_focus(widget); | |
497 | - | |
498 | - /* continue normal event processing: */ | |
499 | - return (FALSE); | |
500 | -} | |
501 | - | |
502 | 506 | /* the new GTK display function: */ |
503 | 507 | TME_ELEMENT_SUB_NEW_DECL(tme_host_gtk,display) { |
504 | - struct tme_gdk_display *display; | |
508 | + _tme_gtk_display *display; | |
509 | +#if GTK_MAJOR_VERSION == 3 | |
505 | 510 | GdkRectangle workarea; |
511 | +#endif | |
506 | 512 | int rc; |
507 | 513 | |
508 | 514 | /* GTK requires program to be running non-setuid */ |
@@ -513,12 +519,14 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_gtk,display) { | ||
513 | 519 | if(rc = !_tme_gtk_init()) return rc; |
514 | 520 | |
515 | 521 | /* start our data structure: */ |
516 | - display = tme_new0(struct tme_gdk_display, 1); | |
522 | + display = tme_new0(_tme_gtk_display, 1); | |
517 | 523 | tme_display_init(element, display); |
518 | 524 | |
519 | 525 | /* recover our data structure: */ |
520 | 526 | display = element->tme_element_private; |
521 | 527 | |
528 | + // display->tme_gtk_application = gtk_application_new("org.phabrics.tme", G_APPLICATION_DEFAULT_FLAGS); | |
529 | + | |
522 | 530 | display->tme_gdk_display = gdk_display_get_default(); |
523 | 531 | |
524 | 532 | display->tme_gdk_display_seat = gdk_display_get_default_seat(display->tme_gdk_display); |
@@ -50,8 +50,10 @@ _TME_RCSID("$Id: gtk-display.h,v 1.10 2009/08/28 01:29:47 fredette Exp $"); | ||
50 | 50 | /* types: */ |
51 | 51 | |
52 | 52 | /* a display: */ |
53 | -struct tme_gdk_display { | |
54 | - | |
53 | +typedef struct tme_gtk_display { | |
54 | + /* the GTK application structure */ | |
55 | + GtkApplication *tme_gtk_application; | |
56 | + | |
55 | 57 | /* the generic display structure */ |
56 | 58 | struct tme_display display; |
57 | 59 |
@@ -64,10 +66,10 @@ struct tme_gdk_display { | ||
64 | 66 | #if GTK_MAJOR_VERSION == 3 |
65 | 67 | GdkMonitor *tme_gdk_display_monitor; |
66 | 68 | #endif |
67 | -}; | |
69 | +} _tme_gtk_display, *tme_gtk_display; | |
68 | 70 | |
69 | 71 | /* a screen: */ |
70 | -struct tme_gtk_screen { | |
72 | +typedef struct tme_gtk_screen { | |
71 | 73 | |
72 | 74 | /* the generic screen structure */ |
73 | 75 | struct tme_screen screen; |
@@ -99,7 +101,7 @@ struct tme_gtk_screen { | ||
99 | 101 | for the framebuffer event box: */ |
100 | 102 | //GdkEventMask tme_gtk_screen_mouse_events_old; |
101 | 103 | |
102 | -}; | |
104 | +} _tme_gtk_screen, *tme_gtk_screen; | |
103 | 105 | |
104 | 106 | /* a menu item: */ |
105 | 107 | struct tme_display_menu_item { |
@@ -112,7 +114,6 @@ struct tme_display_menu_item { | ||
112 | 114 | /* prototypes: */ |
113 | 115 | void _tme_gtk_keyboard_attach _TME_P((struct tme_gtk_screen *)); |
114 | 116 | void _tme_gtk_mouse_attach _TME_P((struct tme_gtk_screen *)); |
115 | -gint _tme_display_enter_focus _TME_P((GtkWidget *, GdkEvent *, gpointer)); | |
116 | 117 | GtkWidget *_tme_display_menu_radio _TME_P((struct tme_gtk_screen *, struct tme_display_menu_item *, int num_items)); |
117 | 118 | |
118 | 119 | #endif /* _HOST_GTK_DISPLAY_H */ |
@@ -44,91 +44,61 @@ _TME_RCSID("$Id: gtk-keyboard.c,v 1.10 2007/02/15 02:15:41 fredette Exp $"); | ||
44 | 44 | /* types: */ |
45 | 45 | |
46 | 46 | /* this is a GTK callback for a key press or release event: */ |
47 | -static int | |
48 | -_tme_gtk_keyboard_key_event(GtkWidget *widget, | |
49 | - GdkEvent *gdk_event_raw, | |
50 | - struct tme_gtk_screen *screen) | |
47 | +static gboolean | |
48 | +_tme_gtk_keyboard_key_down( | |
49 | + GtkEventControllerKey* self, | |
50 | + guint keyval, | |
51 | + guint keycode, | |
52 | + GdkModifierType* state, | |
53 | + struct tme_display *display) | |
51 | 54 | { |
52 | - struct tme_display *display; | |
53 | - GdkEventKey *gdk_event; | |
54 | - struct tme_keyboard_event tme_event; | |
55 | - | |
56 | - /* make a tme event from this gdk event: */ | |
57 | - gdk_event = &gdk_event_raw->key; | |
58 | - tme_event.tme_keyboard_event_type | |
59 | - = (gdk_event_get_event_type(gdk_event) == GDK_KEY_PRESS | |
60 | - ? TME_KEYBOARD_EVENT_PRESS | |
61 | - : TME_KEYBOARD_EVENT_RELEASE); | |
62 | - tme_event.tme_keyboard_event_modifiers | |
63 | - = gdk_event->state; | |
64 | - tme_event.tme_keyboard_event_keyval | |
65 | - = gdk_event->keyval; | |
66 | - tme_event.tme_keyboard_event_time | |
67 | - = gdk_event->time; | |
68 | - | |
69 | - /* recover our data structure: */ | |
70 | - display = screen->screen.tme_screen_display; | |
71 | - | |
72 | - /* lock the mutex: */ | |
73 | - tme_mutex_lock(&display->tme_display_mutex); | |
74 | - | |
75 | - /* if this is a press of the mouse mode off key, turn mouse mode off | |
76 | - and return now: */ | |
77 | - if (gdk_event_get_event_type(gdk_event) == GDK_KEY_PRESS | |
78 | - && (gdk_event->keyval | |
79 | - == screen->tme_gtk_screen_mouse_keyval)) { | |
80 | - _tme_gtk_mouse_mode_off(screen, | |
81 | - gdk_event->time); | |
82 | - | |
83 | - /* unlock the mutex: */ | |
84 | - tme_mutex_unlock(&display->tme_display_mutex); | |
85 | - | |
86 | - return (TRUE); | |
87 | - } | |
88 | - | |
89 | - _tme_keyboard_key_event(&tme_event, display); | |
90 | - | |
91 | - /* unlock the mutex: */ | |
92 | - tme_mutex_unlock(&display->tme_display_mutex); | |
55 | + return _tme_keyboard_key_event(TRUE, keyval, display); | |
56 | +} | |
93 | 57 | |
94 | - /* don't process this event any further: */ | |
95 | - return (TRUE); | |
58 | +static gboolean | |
59 | +_tme_gtk_keyboard_key_up( | |
60 | + GtkEventControllerKey* self, | |
61 | + guint keyval, | |
62 | + guint keycode, | |
63 | + GdkModifierType* state, | |
64 | + struct tme_display *display) | |
65 | +{ | |
66 | + return _tme_keyboard_key_event(FALSE, keyval, display); | |
96 | 67 | } |
97 | 68 | |
98 | 69 | /* this attaches the GTK keyboard to a new screen: */ |
99 | 70 | void |
100 | 71 | _tme_gtk_keyboard_attach(struct tme_gtk_screen *screen) |
101 | 72 | { |
73 | + GtkEventControllerKey *key; | |
74 | + GtkEventControllerMotion *motion; | |
102 | 75 | |
103 | - /* make sure the event box for the framebuffer gets enter, key_press | |
104 | - and key_release events. we have to add these latter two events | |
105 | - to both the event box widget itself, and the top-level window, | |
106 | - since GTK 1.x appears to not select KeyRelease events at the | |
107 | - top-level: */ | |
108 | - gtk_widget_add_events(screen->tme_gtk_screen_gtkframe, | |
109 | - GDK_ENTER_NOTIFY_MASK | |
110 | - | GDK_KEY_PRESS_MASK | |
111 | - | GDK_KEY_RELEASE_MASK); | |
112 | - gtk_widget_add_events (gtk_widget_get_toplevel(screen->tme_gtk_screen_gtkframe), | |
113 | - GDK_KEY_PRESS_MASK | |
114 | - | GDK_KEY_RELEASE_MASK); | |
115 | - | |
116 | - /* set a signal handler for these events: */ | |
117 | - g_signal_connect(screen->tme_gtk_screen_gtkframe, | |
118 | - "enter_notify_event", | |
119 | - G_CALLBACK(_tme_display_enter_focus), | |
120 | - NULL); | |
121 | - g_signal_connect_after(screen->tme_gtk_screen_gtkframe, | |
122 | - "key_press_event", | |
123 | - G_CALLBACK(_tme_gtk_keyboard_key_event), | |
124 | - screen); | |
125 | - g_signal_connect_after(screen->tme_gtk_screen_gtkframe, | |
126 | - "key_release_event", | |
127 | - G_CALLBACK(_tme_gtk_keyboard_key_event), | |
128 | - screen); | |
76 | + motion=gtk_event_controller_motion_new(screen->tme_gtk_screen_gtkframe); | |
77 | + gtk_widget_add_controller(screen->tme_gtk_screen_gtkframe, GTK_EVENT_CONTROLLER(motion)); | |
78 | + | |
79 | + /* on entering window, grab keyboard focus: */ | |
80 | + g_signal_connect_swapped(motion, | |
81 | + "enter", | |
82 | + G_CALLBACK(gtk_widget_grab_focus), | |
83 | + screen->tme_gtk_screen_gtkframe); | |
84 | + | |
85 | + /* set the signal handler for the key events: */ | |
86 | + key=gtk_event_controller_key_new(screen->tme_gtk_screen_gtkframe); | |
87 | + | |
88 | + gtk_widget_add_controller(screen->tme_gtk_screen_gtkframe, GTK_EVENT_CONTROLLER(key)); | |
89 | + | |
90 | + g_signal_connect_after(key, | |
91 | + "key-pressed", | |
92 | + G_CALLBACK(_tme_gtk_keyboard_key_down), | |
93 | + screen->screen.tme_screen_display); | |
94 | + g_signal_connect_after(key, | |
95 | + "key-released", | |
96 | + G_CALLBACK(_tme_gtk_keyboard_key_up), | |
97 | + screen->screen.tme_screen_display); | |
129 | 98 | |
130 | 99 | /* the event box can focus, and have it grab the focus now: */ |
131 | 100 | gtk_widget_set_can_focus(screen->tme_gtk_screen_gtkframe, TRUE); |
132 | 101 | gtk_widget_grab_focus(screen->tme_gtk_screen_gtkframe); |
102 | + | |
133 | 103 | } |
134 | 104 |
@@ -119,7 +119,7 @@ _tme_gtk_mouse_ebox_event(GtkWidget *widget, | ||
119 | 119 | GdkEvent *gdk_event_raw, |
120 | 120 | struct tme_gtk_screen *screen) |
121 | 121 | { |
122 | - struct tme_gdk_display *display; | |
122 | + struct tme_gtk_display *display; | |
123 | 123 | int rc; |
124 | 124 | char *status; |
125 | 125 | GdkWindow *window; |
@@ -215,7 +215,7 @@ void | ||
215 | 215 | _tme_gtk_mouse_mode_off(struct tme_gtk_screen *screen, |
216 | 216 | guint32 time) |
217 | 217 | { |
218 | - struct tme_gdk_display *display; | |
218 | + struct tme_gtk_display *display; | |
219 | 219 | |
220 | 220 | /* get the display: */ |
221 | 221 | display = screen->screen.tme_screen_display; |
@@ -166,7 +166,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_rfb,display) { | ||
166 | 166 | bpp); |
167 | 167 | server->alwaysShared = TRUE; |
168 | 168 | server->ptrAddEvent = _tme_mouse_buttons_event; |
169 | - server->kbdAddEvent = _tme_keyboard_key_press; | |
169 | + server->kbdAddEvent = _tme_keyboard_key_event; | |
170 | 170 | server->newClientHook = _tme_rfb_newclient; |
171 | 171 | // server->httpDir = "../webclients"; |
172 | 172 | // server->httpEnableProxyConnect = TRUE; |
@@ -273,14 +273,14 @@ _tme_sdl_display_update(struct tme_display *display) { | ||
273 | 273 | switch (e.window.event) { |
274 | 274 | case SDL_WINDOWEVENT_FOCUS_LOST: |
275 | 275 | if (rightAltKeyDown) { |
276 | - _tme_keyboard_key_press(FALSE, SDLK_RALT, display); | |
276 | + _tme_keyboard_key_event(FALSE, SDLK_RALT, display); | |
277 | 277 | rightAltKeyDown = FALSE; |
278 | 278 | tme_log(&display->tme_display_element->tme_element_log_handle, 0, TME_OK, |
279 | 279 | (&display->tme_display_element->tme_element_log_handle, |
280 | 280 | _("released right Alt key\n"))); |
281 | 281 | } |
282 | 282 | if (leftAltKeyDown) { |
283 | - _tme_keyboard_key_press(FALSE, SDLK_LALT, display); | |
283 | + _tme_keyboard_key_event(FALSE, SDLK_LALT, display); | |
284 | 284 | leftAltKeyDown = FALSE; |
285 | 285 | tme_log(&display->tme_display_element->tme_element_log_handle, 0, TME_OK, |
286 | 286 | (&display->tme_display_element->tme_element_log_handle, |
@@ -343,7 +343,7 @@ _tme_sdl_display_update(struct tme_display *display) { | ||
343 | 343 | if (viewOnly) |
344 | 344 | break; |
345 | 345 | tme_keyboard_keyval_t sym = SDL_key2rfbKeySym(&e.key); |
346 | - _tme_keyboard_key_press(e.type == SDL_KEYDOWN ? TRUE : FALSE, | |
346 | + _tme_keyboard_key_event(e.type == SDL_KEYDOWN ? TRUE : FALSE, | |
347 | 347 | (sym) ? (sym) : (e.key.keysym.sym), display); |
348 | 348 | if (e.key.keysym.sym == SDLK_RALT) |
349 | 349 | rightAltKeyDown = e.type == SDL_KEYDOWN; |
@@ -355,8 +355,8 @@ _tme_sdl_display_update(struct tme_display *display) { | ||
355 | 355 | if (viewOnly) |
356 | 356 | break; |
357 | 357 | tme_keyboard_keyval_t sym = utf8char2rfbKeySym(e.text.text); |
358 | - _tme_keyboard_key_press(TRUE, sym, display); | |
359 | - _tme_keyboard_key_press(FALSE, sym, display); | |
358 | + _tme_keyboard_key_event(TRUE, sym, display); | |
359 | + _tme_keyboard_key_event(FALSE, sym, display); | |
360 | 360 | #endif |
361 | 361 | break; |
362 | 362 | default: |