From 6922f0e16a4aa9873c9f9868b26a9b8ab68ac939 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 5 Sep 2019 13:17:21 +0200 Subject: [PATCH] x11: Minor refactor of input focus handling code Instead of open coding the X11 focus management in display.c, expose it as a single function with similar arguments to its MetaDisplay counterpart. This just means less X11 specifics in display.c. Closes: https://gitlab.gnome.org/GNOME/mutter/issues/751 --- src/core/display.c | 19 ++--------------- src/x11/meta-x11-display-private.h | 6 +++--- src/x11/meta-x11-display.c | 33 ++++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/core/display.c b/src/core/display.c index 2ddcbbc1f..82c9cd108 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -1372,23 +1372,8 @@ meta_display_set_input_focus (MetaDisplay *display, if (display->x11_display) { - MetaX11Display *x11_display = display->x11_display; - Window xwindow; - gulong serial; - - meta_x11_error_trap_push (x11_display); - - if (window) - xwindow = focus_frame ? window->frame->xwindow : window->xwindow; - else - xwindow = x11_display->no_focus_window; - - meta_x11_display_set_input_focus (x11_display, xwindow, timestamp); - serial = XNextRequest (x11_display->xdisplay); - - meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); - - meta_x11_error_trap_pop (display->x11_display); + meta_x11_display_set_input_focus (display->x11_display, window, + focus_frame, timestamp); } meta_display_update_focus_window (display, window); diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h index 92951844e..7c61d7b0d 100644 --- a/src/x11/meta-x11-display-private.h +++ b/src/x11/meta-x11-display-private.h @@ -224,7 +224,6 @@ void meta_x11_display_create_guard_window (MetaX11Display *x11_display); /* make a request to ensure the event serial has changed */ void meta_x11_display_increment_event_serial (MetaX11Display *x11_display); -void meta_x11_display_update_active_window_hint (MetaX11Display *x11_display); guint32 meta_x11_display_get_current_time_roundtrip (MetaX11Display *x11_display); @@ -250,8 +249,9 @@ void meta_x11_display_update_focus_window (MetaX11Display *x11_display, gulong serial, gboolean focused_by_us); void meta_x11_display_set_input_focus (MetaX11Display *x11_display, - Window xwindow, - guint32 timestamp); + MetaWindow *window, + gboolean focus_frame, + uint32_t timestamp); const gchar * meta_x11_get_display_name (void); diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c index 5f2e71c44..77283d323 100644 --- a/src/x11/meta-x11-display.c +++ b/src/x11/meta-x11-display.c @@ -1825,7 +1825,7 @@ meta_x11_display_increment_event_serial (MetaX11Display *x11_display) x11_display->atom__MOTIF_WM_HINTS); } -void +static void meta_x11_display_update_active_window_hint (MetaX11Display *x11_display) { MetaWindow *focus_window; @@ -1867,10 +1867,10 @@ meta_x11_display_update_focus_window (MetaX11Display *x11_display, meta_x11_display_update_active_window_hint (x11_display); } -void -meta_x11_display_set_input_focus (MetaX11Display *x11_display, - Window xwindow, - guint32 timestamp) +static void +meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display, + Window xwindow, + uint32_t timestamp) { meta_x11_error_trap_push (x11_display); @@ -1900,6 +1900,27 @@ meta_x11_display_set_input_focus (MetaX11Display *x11_display, meta_x11_error_trap_pop (x11_display); } +void +meta_x11_display_set_input_focus (MetaX11Display *x11_display, + MetaWindow *window, + gboolean focus_frame, + uint32_t timestamp) +{ + Window xwindow; + gulong serial; + + if (window) + xwindow = focus_frame ? window->frame->xwindow : window->xwindow; + else + xwindow = x11_display->no_focus_window; + + meta_x11_error_trap_push (x11_display); + meta_x11_display_set_input_focus_internal (x11_display, xwindow, timestamp); + serial = XNextRequest (x11_display->xdisplay); + meta_x11_display_update_focus_window (x11_display, xwindow, serial, TRUE); + meta_x11_error_trap_pop (x11_display); +} + void meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display, Window window, @@ -1909,7 +1930,7 @@ meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display, meta_display_unset_input_focus (x11_display->display, timestamp); serial = XNextRequest (x11_display->xdisplay); - meta_x11_display_set_input_focus (x11_display, window, timestamp); + meta_x11_display_set_input_focus_internal (x11_display, window, timestamp); meta_x11_display_update_focus_window (x11_display, window, serial, TRUE); }