Révision | dc8859ae93959bc92b7d07bcd9b0ea9e5e21cff8 (tree) |
---|---|
l'heure | 2023-02-16 21:08:52 |
Auteur | phabrics <phabrics@phab...> |
Commiter | phabrics |
Display changes for GTK4.
@@ -119,6 +119,7 @@ _tme_gtk_screen_scale_double(GtkWidget *widget, | ||
119 | 119 | _tme_screen_scale_set(screen, TME_FB_XLAT_SCALE_DOUBLE ); |
120 | 120 | } |
121 | 121 | |
122 | +#if GTK_MAJOR_VERSION == 3 | |
122 | 123 | /* this sets the screen size: */ |
123 | 124 | static inline void |
124 | 125 | _tme_screen_format_set(struct tme_gtk_screen *screen, |
@@ -183,14 +184,6 @@ _tme_gtk_screen_format_rgb16_565(GtkWidget *widget, | ||
183 | 184 | _tme_screen_format_set(screen, CAIRO_FORMAT_RGB16_565); |
184 | 185 | } |
185 | 186 | |
186 | -static struct tme_display_menu_item scale_items[] = | |
187 | - { | |
188 | - { _("Default"), G_CALLBACK(_tme_gtk_screen_scale_default) }, | |
189 | - { _("Half"), G_CALLBACK(_tme_gtk_screen_scale_half) }, | |
190 | - { _("Full"), G_CALLBACK(_tme_gtk_screen_scale_full) }, | |
191 | - { _("Double"), G_CALLBACK(_tme_gtk_screen_scale_double) } | |
192 | - }; | |
193 | - | |
194 | 187 | static struct tme_display_menu_item format_items[] = |
195 | 188 | { |
196 | 189 | { _("ARGB32"), G_CALLBACK(_tme_gtk_screen_format_argb32) }, |
@@ -200,6 +193,16 @@ static struct tme_display_menu_item format_items[] = | ||
200 | 193 | { _("RGB16_565"), G_CALLBACK(_tme_gtk_screen_format_rgb16_565) } |
201 | 194 | }; |
202 | 195 | |
196 | +#endif | |
197 | + | |
198 | +static struct tme_display_menu_item scale_items[] = | |
199 | + { | |
200 | + { _("Default"), G_CALLBACK(_tme_gtk_screen_scale_default) }, | |
201 | + { _("Half"), G_CALLBACK(_tme_gtk_screen_scale_half) }, | |
202 | + { _("Full"), G_CALLBACK(_tme_gtk_screen_scale_full) }, | |
203 | + { _("Double"), G_CALLBACK(_tme_gtk_screen_scale_double) } | |
204 | + }; | |
205 | + | |
203 | 206 | /* Screen-specific size request */ |
204 | 207 | static void _tme_gtk_screen_resize(struct tme_gtk_screen *screen) { |
205 | 208 | struct tme_fb_connection *conn_fb = screen->screen.tme_screen_fb; |
@@ -210,75 +213,23 @@ static void _tme_gtk_screen_resize(struct tme_gtk_screen *screen) { | ||
210 | 213 | conn_fb->tme_fb_connection_height); |
211 | 214 | } |
212 | 215 | |
213 | -/* Create a similar image surface to the screen's target surface (i.e., backing store) */ | |
214 | -static inline cairo_surface_t * | |
215 | -_tme_gtk_screen_create_similar_image(GdkWindow *window, | |
216 | - cairo_format_t format, | |
217 | - int width, | |
218 | - int height) | |
219 | -{ | |
220 | - cairo_surface_t *surface; | |
221 | - | |
222 | -#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION < 10 | |
223 | - surface = | |
224 | - cairo_image_surface_create(format, | |
225 | - width, | |
226 | - height); | |
227 | -#else | |
228 | - surface = | |
229 | - gdk_window_create_similar_image_surface(window, | |
230 | - format, | |
231 | - width, | |
232 | - height, | |
233 | - 0); | |
234 | -#endif | |
235 | - return surface; | |
236 | -} | |
237 | - | |
238 | 216 | /* Create a new surface of the appropriate size to store our scribbles */ |
239 | 217 | static void |
240 | -_tme_gtk_screen_init(GtkWidget *widget, | |
241 | - struct tme_gtk_screen *screen) | |
242 | -{ | |
243 | - tme_uint8_t *bitmap_data; | |
244 | - int bitmap_width, bitmap_height; | |
245 | - unsigned int y; | |
246 | - | |
247 | - screen->tme_gtk_screen_surface = | |
248 | - _tme_gtk_screen_create_similar_image(gtk_widget_get_window(widget), | |
249 | - CAIRO_FORMAT_A1, | |
250 | - gtk_widget_get_allocated_width(widget), | |
251 | - gtk_widget_get_allocated_height(widget)); | |
252 | - | |
253 | - /* create an image surface of an alternating-bits area. */ | |
254 | - bitmap_data = cairo_image_surface_get_data(screen->tme_gtk_screen_surface); | |
255 | - assert(bitmap_data != NULL); | |
256 | - bitmap_width = cairo_image_surface_get_width(screen->tme_gtk_screen_surface) / 8; | |
257 | - bitmap_height = cairo_image_surface_get_height(screen->tme_gtk_screen_surface); | |
258 | - cairo_surface_flush(screen->tme_gtk_screen_surface); | |
259 | - for (y = 0; | |
260 | - y < bitmap_height; | |
261 | - y++) { | |
262 | - memset(bitmap_data + y * bitmap_width, | |
263 | - (y & 1 | |
264 | - ? 0x33 | |
265 | - : 0xcc), | |
266 | - bitmap_width); | |
267 | - } | |
268 | - cairo_surface_mark_dirty(screen->tme_gtk_screen_surface); | |
269 | -} | |
270 | - | |
271 | -/* Create a new surface of the appropriate size to store our scribbles */ | |
272 | -static gboolean | |
273 | 218 | _tme_gtk_screen_configure(GtkWidget *widget, |
219 | +#if GTK_MAJOR_VERSION == 4 | |
220 | + int width, | |
221 | + int height, | |
222 | +#elif GTK_MAJOR_VERSION == 3 | |
274 | 223 | GdkEventConfigure *event, |
224 | +#endif | |
275 | 225 | gpointer _screen) |
276 | 226 | { |
277 | 227 | struct tme_gtk_screen *screen; |
278 | 228 | struct tme_display *display; |
279 | 229 | struct tme_fb_connection *conn_fb; |
230 | +#if GTK_MAJOR_VERSION == 3 | |
280 | 231 | GdkWindow *window; |
281 | - int scale; | |
232 | +#endif | |
282 | 233 | |
283 | 234 | screen = (struct tme_gtk_screen *) _screen; |
284 | 235 |
@@ -288,8 +239,20 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
288 | 239 | /* lock our mutex: */ |
289 | 240 | tme_mutex_lock(&display->tme_display_mutex); |
290 | 241 | |
291 | - cairo_surface_destroy(screen->tme_gtk_screen_surface); | |
242 | + if(screen->tme_gtk_screen_surface) { | |
243 | + cairo_surface_destroy(screen->tme_gtk_screen_surface); | |
244 | + screen->tme_gtk_screen_surface = NULL; | |
245 | + } | |
292 | 246 | |
247 | +#if GTK_MAJOR_VERSION == 4 | |
248 | + if (gtk_native_get_surface(gtk_widget_get_native(widget))) { | |
249 | + screen->tme_gtk_screen_surface = | |
250 | + gdk_surface_create_similar_surface(gtk_native_get_surface(gtk_widget_get_native(widget)), | |
251 | + CAIRO_CONTENT_COLOR, | |
252 | + gtk_widget_get_width(widget), | |
253 | + gtk_widget_get_height(widget)); | |
254 | + } | |
255 | +#elif GTK_MAJOR_VERSION == 3 | |
293 | 256 | window = gtk_widget_get_window(screen->tme_gtk_screen_gtkframe); |
294 | 257 | |
295 | 258 | screen->screen.tme_screen_scale = gdk_window_get_scale_factor(window); |
@@ -300,6 +263,7 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
300 | 263 | gdk_window_get_width(window) * screen->screen.tme_screen_scale, |
301 | 264 | gdk_window_get_height(window) * screen->screen.tme_screen_scale, |
302 | 265 | screen->screen.tme_screen_scale); |
266 | +#endif | |
303 | 267 | |
304 | 268 | conn_fb = screen->screen.tme_screen_fb; |
305 | 269 |
@@ -322,7 +286,7 @@ _tme_gtk_screen_configure(GtkWidget *widget, | ||
322 | 286 | tme_mutex_unlock(&display->tme_display_mutex); |
323 | 287 | |
324 | 288 | /* We've handled the configure event, no need for further processing. */ |
325 | - return TRUE; | |
289 | + // return TRUE; | |
326 | 290 | } |
327 | 291 | |
328 | 292 | /* this is called before the screen's display is updated: */ |
@@ -341,6 +305,10 @@ _tme_gtk_screen_redraw(struct tme_gtk_screen *screen, int x, int y, int w, int h | ||
341 | 305 | static gboolean |
342 | 306 | _tme_gtk_screen_draw(GtkWidget *widget, |
343 | 307 | cairo_t *cr, |
308 | +#if GTK_MAJOR_VERSION == 4 | |
309 | + int width, | |
310 | + int height, | |
311 | +#endif | |
344 | 312 | gpointer _screen) |
345 | 313 | { |
346 | 314 | struct tme_display *display; |
@@ -369,8 +337,6 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
369 | 337 | struct tme_connection *conn) |
370 | 338 | { |
371 | 339 | struct tme_gtk_screen *screen; |
372 | - GdkDisplay *gdkdisplay; | |
373 | - GdkDeviceManager *devices; | |
374 | 340 | GtkWidget *menu_bar; |
375 | 341 | GtkWidget *menu; |
376 | 342 | GtkWidget *submenu; |
@@ -378,12 +344,15 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
378 | 344 | |
379 | 345 | screen = tme_screen_new(display, struct tme_gtk_screen, conn); |
380 | 346 | |
381 | - screen->screen.tme_screen_scale = gdk_monitor_get_scale_factor(display->tme_gdk_display_monitor); | |
382 | - | |
383 | 347 | /* create the top-level window, and allow it to shrink, grow, |
384 | 348 | and auto-shrink: */ |
385 | - screen->tme_gtk_screen_window | |
386 | - = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
349 | + screen->tme_gtk_screen_window = | |
350 | +#if GTK_MAJOR_VERSION == 4 | |
351 | + gtk_window_new(); | |
352 | +#elif GTK_MAJOR_VERSION == 3 | |
353 | + gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
354 | + screen->screen.tme_screen_scale = gdk_monitor_get_scale_factor(display->tme_gdk_display_monitor); | |
355 | +#endif | |
387 | 356 | |
388 | 357 | gtk_window_set_resizable(GTK_WINDOW(screen->tme_gtk_screen_window), FALSE); |
389 | 358 |
@@ -415,6 +384,7 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
415 | 384 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); |
416 | 385 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item); |
417 | 386 | |
387 | +#if GTK_MAJOR_VERSION == 4 | |
418 | 388 | /* create the Screen colormap submenu: */ |
419 | 389 | submenu = _tme_display_menu_radio(screen, format_items, TME_ARRAY_ELS(format_items)); |
420 | 390 |
@@ -423,7 +393,8 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
423 | 393 | // gtk_widget_show(menu_item); |
424 | 394 | gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); |
425 | 395 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item); |
426 | - | |
396 | +#endif | |
397 | + | |
427 | 398 | /* create the Screen menu bar item, attach the menu to it, and |
428 | 399 | attach the menu bar item to the menu bar: */ |
429 | 400 | menu_item = gtk_menu_item_new_with_label("Screen"); |
@@ -446,11 +417,18 @@ _tme_gtk_screen_new(struct tme_gdk_display *display, | ||
446 | 417 | screen->tme_gtk_screen_gtkframe, |
447 | 418 | FALSE, FALSE, 0); |
448 | 419 | |
420 | +#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); | |
423 | + g_signal_connect_after(screen->tme_gtk_screen_gtkframe, "resize", | |
424 | + G_CALLBACK(_tme_gtk_screen_configure), screen); | |
425 | + | |
426 | +#elif GTK_MAJOR_VERSION == 3 | |
449 | 427 | g_signal_connect(screen->tme_gtk_screen_gtkframe, "draw", |
450 | 428 | G_CALLBACK(_tme_gtk_screen_draw), screen); |
451 | - | |
452 | 429 | g_signal_connect(screen->tme_gtk_screen_gtkframe, "configure-event", |
453 | 430 | G_CALLBACK(_tme_gtk_screen_configure), screen); |
431 | +#endif | |
454 | 432 | |
455 | 433 | /* attach the mouse to this screen: */ |
456 | 434 | _tme_gtk_mouse_attach(screen); |
@@ -543,11 +521,15 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_gtk,display) { | ||
543 | 521 | |
544 | 522 | display->tme_gdk_display = gdk_display_get_default(); |
545 | 523 | |
546 | - display->tme_gdk_display_cursor | |
547 | - = gdk_cursor_new_for_display(display->tme_gdk_display, GDK_BLANK_CURSOR); | |
548 | - | |
549 | 524 | display->tme_gdk_display_seat = gdk_display_get_default_seat(display->tme_gdk_display); |
550 | 525 | |
526 | + display->tme_gdk_display_cursor = | |
527 | +#if GTK_MAJOR_VERSION == 4 | |
528 | + GDK_BLANK_CURSOR; | |
529 | + // = gdk_cursor_new_from_name("none", NULL); | |
530 | +#elif GTK_MAJOR_VERSION == 3 | |
531 | + gdk_cursor_new_for_display(display->tme_gdk_display, GDK_BLANK_CURSOR); | |
532 | + | |
551 | 533 | display->tme_gdk_display_monitor = gdk_display_get_primary_monitor(display->tme_gdk_display); |
552 | 534 | |
553 | 535 | gdk_monitor_get_workarea(display->tme_gdk_display_monitor, &workarea); |
@@ -558,6 +540,7 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_gtk,display) { | ||
558 | 540 | display->display.tme_screen_width = workarea.width; |
559 | 541 | display->display.tme_screen_height = workarea.height; |
560 | 542 | } |
543 | +#endif | |
561 | 544 | |
562 | 545 | /* set the display-specific functions: */ |
563 | 546 | display->display.tme_display_bell = _tme_gtk_display_bell; |
@@ -61,7 +61,9 @@ struct tme_gdk_display { | ||
61 | 61 | |
62 | 62 | GdkSeat *tme_gdk_display_seat; |
63 | 63 | |
64 | +#if GTK_MAJOR_VERSION == 3 | |
64 | 65 | GdkMonitor *tme_gdk_display_monitor; |
66 | +#endif | |
65 | 67 | }; |
66 | 68 | |
67 | 69 | /* a screen: */ |