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
This commit is contained in:
Carlos Garnacho 2019-09-05 13:17:21 +02:00 committed by Georges Basile Stavracas Neto
parent 31df06d94e
commit 6922f0e16a
3 changed files with 32 additions and 26 deletions

View File

@ -1372,23 +1372,8 @@ meta_display_set_input_focus (MetaDisplay *display,
if (display->x11_display) if (display->x11_display)
{ {
MetaX11Display *x11_display = display->x11_display; meta_x11_display_set_input_focus (display->x11_display, window,
Window xwindow; focus_frame, timestamp);
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_display_update_focus_window (display, window); meta_display_update_focus_window (display, window);

View File

@ -224,7 +224,6 @@ void meta_x11_display_create_guard_window (MetaX11Display *x11_display);
/* make a request to ensure the event serial has changed */ /* make a request to ensure the event serial has changed */
void meta_x11_display_increment_event_serial (MetaX11Display *x11_display); 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); 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, gulong serial,
gboolean focused_by_us); gboolean focused_by_us);
void meta_x11_display_set_input_focus (MetaX11Display *x11_display, void meta_x11_display_set_input_focus (MetaX11Display *x11_display,
Window xwindow, MetaWindow *window,
guint32 timestamp); gboolean focus_frame,
uint32_t timestamp);
const gchar * meta_x11_get_display_name (void); const gchar * meta_x11_get_display_name (void);

View File

@ -1825,7 +1825,7 @@ meta_x11_display_increment_event_serial (MetaX11Display *x11_display)
x11_display->atom__MOTIF_WM_HINTS); x11_display->atom__MOTIF_WM_HINTS);
} }
void static void
meta_x11_display_update_active_window_hint (MetaX11Display *x11_display) meta_x11_display_update_active_window_hint (MetaX11Display *x11_display)
{ {
MetaWindow *focus_window; 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); meta_x11_display_update_active_window_hint (x11_display);
} }
void static void
meta_x11_display_set_input_focus (MetaX11Display *x11_display, meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display,
Window xwindow, Window xwindow,
guint32 timestamp) uint32_t timestamp)
{ {
meta_x11_error_trap_push (x11_display); 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); 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 void
meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display, meta_x11_display_set_input_focus_xwindow (MetaX11Display *x11_display,
Window window, 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); meta_display_unset_input_focus (x11_display->display, timestamp);
serial = XNextRequest (x11_display->xdisplay); 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); meta_x11_display_update_focus_window (x11_display, window, serial, TRUE);
} }