diff options
author | David Robillard <d@drobilla.net> | 2024-12-01 21:02:51 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-12-01 21:20:03 -0500 |
commit | eafa5f3bc6a71bfc9b7b36d65dd031de0f868539 (patch) | |
tree | 5c7a808f69347e433bf62bfb7d7e72c5592cfabe | |
parent | 1441f47023151f4e1ae12f1b86ce68fa341c3a14 (diff) | |
download | suil-eafa5f3bc6a71bfc9b7b36d65dd031de0f868539.tar.gz suil-eafa5f3bc6a71bfc9b7b36d65dd031de0f868539.tar.bz2 suil-eafa5f3bc6a71bfc9b7b36d65dd031de0f868539.zip |
Use more consistent variable names and shrink Gtk/X11 code
-rw-r--r-- | src/x11_in_gtk2.c | 64 | ||||
-rw-r--r-- | src/x11_in_gtk3.c | 83 |
2 files changed, 60 insertions, 87 deletions
diff --git a/src/x11_in_gtk2.c b/src/x11_in_gtk2.c index 2828b84..e8e4521 100644 --- a/src/x11_in_gtk2.c +++ b/src/x11_in_gtk2.c @@ -103,21 +103,22 @@ suil_x11_wrapper_realize(GtkWidget* w) // Setup drag/drop proxy from parent/grandparent window GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); Window xwindow = GDK_WINDOW_XID(gwindow); Atom xdnd_proxy_atom = gdk_x11_get_xatom_by_name("XdndProxy"); - Window plugin = (Window)wrap->instance->ui_widget; + Window ui_window = (Window)wrap->instance->ui_widget; while (xwindow) { - XChangeProperty(GDK_WINDOW_XDISPLAY(gwindow), + XChangeProperty(xdisplay, xwindow, xdnd_proxy_atom, XA_WINDOW, 32, PropModeReplace, - (unsigned char*)&plugin, + (unsigned char*)&ui_window, 1); - xwindow = suil_x11_get_parent(GDK_WINDOW_XDISPLAY(gwindow), xwindow); + xwindow = suil_x11_get_parent(xdisplay, xwindow); } } @@ -136,11 +137,11 @@ suil_x11_wrapper_show(GtkWidget* w) static gboolean forward_key_event(SuilX11Wrapper* socket, GdkEvent* gdk_event) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(socket->plug)); - GdkScreen* screen = gdk_visual_get_screen(gdk_window_get_visual(window)); + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(socket->plug)); + GdkScreen* screen = gdk_visual_get_screen(gdk_window_get_visual(gwindow)); Window target_window = 0; - if (gdk_event->any.window == window) { + if (gdk_event->any.window == gwindow) { // Event sent up to the plug window, forward it up to the parent GtkWidget* widget = GTK_WIDGET(socket->instance->host_widget); GdkWindow* parent = gtk_widget_get_parent_window(widget); @@ -164,13 +165,13 @@ forward_key_event(SuilX11Wrapper* socket, GdkEvent* gdk_event) xev.state = gdk_event->key.state; xev.keycode = gdk_event->key.hardware_keycode; - XSendEvent(GDK_WINDOW_XDISPLAY(window), + XSendEvent(GDK_WINDOW_XDISPLAY(gwindow), target_window, False, NoEventMask, (XEvent*)&xev); - return (gdk_event->any.window != window); + return (gdk_event->any.window != gwindow); } static gboolean @@ -185,10 +186,10 @@ idle_size_request(gpointer user_data) static void query_wm_hints(SuilX11Wrapper* wrap) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); long supplied = 0; - XGetWMNormalHints(GDK_WINDOW_XDISPLAY(window), + XGetWMNormalHints(GDK_WINDOW_XDISPLAY(gwindow), (Window)wrap->instance->ui_widget, &wrap->size_hints, &supplied); @@ -200,10 +201,10 @@ query_wm_hints(SuilX11Wrapper* wrap) static void forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(socket->plug)); - if (suil_x11_is_valid_child(GDK_WINDOW_XDISPLAY(window), - GDK_WINDOW_XID(window), - (Window)socket->instance->ui_widget)) { + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(socket->plug)); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)socket->instance->ui_widget; + if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(gwindow), ui_window)) { // Calculate allocation size constrained to X11 limits for widget int width = allocation->width; int height = allocation->height; @@ -223,10 +224,7 @@ forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) } // Resize widget window - XResizeWindow(GDK_WINDOW_XDISPLAY(window), - (Window)socket->instance->ui_widget, - (unsigned)width, - (unsigned)height); + XResizeWindow(xdisplay, ui_window, (unsigned)width, (unsigned)height); // Get actual widget geometry Window root = 0; @@ -235,21 +233,13 @@ forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) unsigned int ww = 0; unsigned int wh = 0; unsigned int ignored = 0; - XGetGeometry(GDK_WINDOW_XDISPLAY(window), - (Window)socket->instance->ui_widget, - &root, - &wx, - &wy, - &ww, - &wh, - &ignored, - &ignored); + XGetGeometry( + xdisplay, ui_window, &root, &wx, &wy, &ww, &wh, &ignored, &ignored); // Center widget in allocation wx = (allocation->width - (int)ww) / 2; wy = (allocation->height - (int)wh) / 2; - XMoveWindow( - GDK_WINDOW_XDISPLAY(window), (Window)socket->instance->ui_widget, wx, wy); + XMoveWindow(xdisplay, ui_window, wx, wy); } else { /* Child has not been realized, so unable to resize now. Queue an idle resize. */ @@ -388,18 +378,16 @@ wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) wrap->wrapper = wrapper; wrap->instance = instance; - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); - GdkDisplay* display = gdk_window_get_display(window); - Display* xdisplay = GDK_WINDOW_XDISPLAY(window); - Window xwindow = (Window)instance->ui_widget; + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)instance->ui_widget; - gdk_display_sync(display); - if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(window), xwindow)) { + gdk_display_sync(gdk_window_get_display(gwindow)); + if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(gwindow), ui_window)) { XWindowAttributes attrs; - XGetWindowAttributes(xdisplay, xwindow, &attrs); + XGetWindowAttributes(xdisplay, ui_window, &attrs); query_wm_hints(wrap); - if (!(wrap->size_hints.flags & PBaseSize)) { // Fall back to using initial size as base size wrap->size_hints.flags |= PBaseSize; diff --git a/src/x11_in_gtk3.c b/src/x11_in_gtk3.c index 4addc03..c956fd5 100644 --- a/src/x11_in_gtk3.c +++ b/src/x11_in_gtk3.c @@ -127,11 +127,11 @@ suil_x11_wrapper_show(GtkWidget* w) static gboolean forward_key_event(SuilX11Wrapper* socket, GdkEvent* gdk_event) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(socket->plug)); - GdkScreen* screen = gdk_visual_get_screen(gdk_window_get_visual(window)); + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(socket->plug)); + GdkScreen* screen = gdk_visual_get_screen(gdk_window_get_visual(gwindow)); Window target_window = 0; - if (gdk_event->any.window == window) { + if (gdk_event->any.window == gwindow) { // Event sent up to the plug window, forward it up to the parent GtkWidget* widget = GTK_WIDGET(socket->instance->host_widget); GdkWindow* parent = gtk_widget_get_parent_window(widget); @@ -155,13 +155,13 @@ forward_key_event(SuilX11Wrapper* socket, GdkEvent* gdk_event) xev.state = gdk_event->key.state; xev.keycode = gdk_event->key.hardware_keycode; - XSendEvent(GDK_WINDOW_XDISPLAY(window), + XSendEvent(GDK_WINDOW_XDISPLAY(gwindow), target_window, False, NoEventMask, (XEvent*)&xev); - return (gdk_event->any.window != window); + return (gdk_event->any.window != gwindow); } static gboolean @@ -178,17 +178,17 @@ idle_size_request(gpointer user_data) static void forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) { - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(socket->plug)); - if (suil_x11_is_valid_child(GDK_WINDOW_XDISPLAY(window), - GDK_WINDOW_XID(window), - (Window)socket->instance->ui_widget)) { + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(socket->plug)); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)socket->instance->ui_widget; + + if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(gwindow), ui_window)) { // Calculate allocation size constrained to X11 limits for widget int width = allocation->width; int height = allocation->height; XSizeHints hints; memset(&hints, 0, sizeof(hints)); - XGetNormalHints( - GDK_WINDOW_XDISPLAY(window), (Window)socket->instance->ui_widget, &hints); + XGetNormalHints(xdisplay, ui_window, &hints); if (hints.flags & PMaxSize) { width = MIN(width, hints.max_width); height = MIN(height, hints.max_height); @@ -199,10 +199,7 @@ forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) } // Resize widget window - XResizeWindow(GDK_WINDOW_XDISPLAY(window), - (Window)socket->instance->ui_widget, - (unsigned)width, - (unsigned)height); + XResizeWindow(xdisplay, ui_window, (unsigned)width, (unsigned)height); // Get actual widget geometry Window root = 0; @@ -211,21 +208,13 @@ forward_size_request(SuilX11Wrapper* socket, GtkAllocation* allocation) unsigned int ww = 0; unsigned int wh = 0; unsigned int ignored = 0; - XGetGeometry(GDK_WINDOW_XDISPLAY(window), - (Window)socket->instance->ui_widget, - &root, - &wx, - &wy, - &ww, - &wh, - &ignored, - &ignored); + XGetGeometry( + xdisplay, ui_window, &root, &wx, &wy, &ww, &wh, &ignored, &ignored); // Center widget in allocation wx = (allocation->width - (int)ww) / 2; wy = (allocation->height - (int)wh) / 2; - XMoveWindow( - GDK_WINDOW_XDISPLAY(window), (Window)socket->instance->ui_widget, wx, wy); + XMoveWindow(xdisplay, ui_window, wx, wy); } else { /* Child has not been realized, so unable to resize now. Queue an idle resize. */ @@ -250,18 +239,16 @@ suil_x11_wrapper_get_preferred_width(GtkWidget* widget, gint* minimum_width, gint* natural_width) { - SuilX11Wrapper* const self = SUIL_X11_WRAPPER(widget); - GdkWindow* const window = gtk_widget_get_window(GTK_WIDGET(self->plug)); - if (suil_x11_is_valid_child(GDK_WINDOW_XDISPLAY(window), - GDK_WINDOW_XID(window), - (Window)self->instance->ui_widget)) { + SuilX11Wrapper* const self = SUIL_X11_WRAPPER(widget); + GdkWindow* const gwindow = gtk_widget_get_window(GTK_WIDGET(self->plug)); + Display* const xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)self->instance->ui_widget; + + if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(gwindow), ui_window)) { XSizeHints hints; memset(&hints, 0, sizeof(hints)); long supplied = 0; - XGetWMNormalHints(GDK_WINDOW_XDISPLAY(window), - (Window)self->instance->ui_widget, - &hints, - &supplied); + XGetWMNormalHints(xdisplay, ui_window, &hints, &supplied); *natural_width = ((hints.flags & PBaseSize) ? hints.base_width : self->initial_width); *minimum_width = @@ -276,18 +263,16 @@ suil_x11_wrapper_get_preferred_height(GtkWidget* widget, gint* minimum_height, gint* natural_height) { - SuilX11Wrapper* const self = SUIL_X11_WRAPPER(widget); - GdkWindow* const window = gtk_widget_get_window(GTK_WIDGET(self->plug)); - if (suil_x11_is_valid_child(GDK_WINDOW_XDISPLAY(window), - GDK_WINDOW_XID(window), - (Window)self->instance->ui_widget)) { + SuilX11Wrapper* const self = SUIL_X11_WRAPPER(widget); + GdkWindow* const gwindow = gtk_widget_get_window(GTK_WIDGET(self->plug)); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)self->instance->ui_widget; + + if (suil_x11_is_valid_child(xdisplay, GDK_WINDOW_XID(gwindow), ui_window)) { XSizeHints hints; memset(&hints, 0, sizeof(hints)); long supplied = 0; - XGetWMNormalHints(GDK_WINDOW_XDISPLAY(window), - (Window)self->instance->ui_widget, - &hints, - &supplied); + XGetWMNormalHints(xdisplay, ui_window, &hints, &supplied); *natural_height = ((hints.flags & PBaseSize) ? hints.base_height : self->initial_height); *minimum_height = @@ -366,15 +351,15 @@ wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) wrap->wrapper = wrapper; wrap->instance = instance; - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); - GdkDisplay* display = gdk_window_get_display(window); - Display* xdisplay = GDK_WINDOW_XDISPLAY(window); - Window xwindow = (Window)instance->ui_widget; + GdkWindow* gwindow = gtk_widget_get_window(GTK_WIDGET(wrap->plug)); + GdkDisplay* display = gdk_window_get_display(gwindow); + Display* xdisplay = GDK_WINDOW_XDISPLAY(gwindow); + Window ui_window = (Window)instance->ui_widget; gdk_display_sync(display); XWindowAttributes attrs; - XGetWindowAttributes(xdisplay, xwindow, &attrs); + XGetWindowAttributes(xdisplay, ui_window, &attrs); wrap->initial_width = attrs.width; wrap->initial_height = attrs.height; |