mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
Move current logical monitor retrieval to the backends
The method used for getting the current logical monitor (the monitor where the pointer cursor is currently at) depends on the backend type, so move that logic to the corresponding backends. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
parent
06770b0dd4
commit
5a8509f895
@ -71,6 +71,8 @@ struct _MetaBackendClass
|
||||
int x,
|
||||
int y);
|
||||
|
||||
MetaLogicalMonitor * (* get_current_logical_monitor) (MetaBackend *backend);
|
||||
|
||||
void (* set_keymap) (MetaBackend *backend,
|
||||
const char *layouts,
|
||||
const char *variants,
|
||||
@ -122,6 +124,8 @@ void meta_backend_warp_pointer (MetaBackend *backend,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
MetaLogicalMonitor * meta_backend_get_current_logical_monitor (MetaBackend *backend);
|
||||
|
||||
struct xkb_keymap * meta_backend_get_keymap (MetaBackend *backend);
|
||||
|
||||
void meta_backend_update_last_device (MetaBackend *backend,
|
||||
|
@ -572,6 +572,12 @@ meta_backend_warp_pointer (MetaBackend *backend,
|
||||
META_BACKEND_GET_CLASS (backend)->warp_pointer (backend, x, y);
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_backend_get_current_logical_monitor (MetaBackend *backend)
|
||||
{
|
||||
return META_BACKEND_GET_CLASS (backend)->get_current_logical_monitor (backend);
|
||||
}
|
||||
|
||||
void
|
||||
meta_backend_set_keymap (MetaBackend *backend,
|
||||
const char *layouts,
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "meta-cursor-renderer-native.h"
|
||||
#include "meta-launcher.h"
|
||||
#include "backends/meta-cursor-tracker-private.h"
|
||||
#include "backends/meta-monitor-manager-private.h"
|
||||
#include "backends/meta-pointer-constraint.h"
|
||||
#include "backends/meta-stage.h"
|
||||
#include "backends/native/meta-clutter-backend-native.h"
|
||||
@ -336,6 +337,18 @@ meta_backend_native_warp_pointer (MetaBackend *backend,
|
||||
meta_cursor_tracker_update_position (cursor_tracker, x, y);
|
||||
}
|
||||
|
||||
static MetaLogicalMonitor *
|
||||
meta_backend_native_get_current_logical_monitor (MetaBackend *backend)
|
||||
{
|
||||
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
int x, y;
|
||||
|
||||
meta_cursor_tracker_get_pointer (cursor_tracker, &x, &y, NULL);
|
||||
return meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_native_set_keymap (MetaBackend *backend,
|
||||
const char *layouts,
|
||||
@ -436,6 +449,9 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
|
||||
backend_class->create_renderer = meta_backend_native_create_renderer;
|
||||
|
||||
backend_class->warp_pointer = meta_backend_native_warp_pointer;
|
||||
|
||||
backend_class->get_current_logical_monitor = meta_backend_native_get_current_logical_monitor;
|
||||
|
||||
backend_class->set_keymap = meta_backend_native_set_keymap;
|
||||
backend_class->get_keymap = meta_backend_native_get_keymap;
|
||||
backend_class->lock_layout_group = meta_backend_native_lock_layout_group;
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "backends/x11/nested/meta-cursor-renderer-x11-nested.h"
|
||||
#include "backends/x11/meta-clutter-backend-x11.h"
|
||||
#include "backends/x11/meta-renderer-x11.h"
|
||||
#include "meta/meta-cursor-tracker.h"
|
||||
#include "meta-cursor-renderer-x11.h"
|
||||
#ifdef HAVE_WAYLAND
|
||||
#include "wayland/meta-wayland.h"
|
||||
@ -92,6 +93,8 @@ struct _MetaBackendX11Private
|
||||
gchar *keymap_variants;
|
||||
gchar *keymap_options;
|
||||
int locked_group;
|
||||
|
||||
MetaLogicalMonitor *cached_current_logical_monitor;
|
||||
};
|
||||
typedef struct _MetaBackendX11Private MetaBackendX11Private;
|
||||
|
||||
@ -447,11 +450,22 @@ on_device_added (ClutterDeviceManager *device_manager,
|
||||
apply_keymap (x11);
|
||||
}
|
||||
|
||||
static void
|
||||
on_monitors_changed (MetaMonitorManager *manager,
|
||||
MetaBackend *backend)
|
||||
{
|
||||
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
|
||||
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
|
||||
|
||||
priv->cached_current_logical_monitor = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_x11_post_init (MetaBackend *backend)
|
||||
{
|
||||
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
|
||||
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
|
||||
MetaMonitorManager *monitor_manager;
|
||||
int major, minor;
|
||||
gboolean has_xi = FALSE;
|
||||
|
||||
@ -500,6 +514,10 @@ meta_backend_x11_post_init (MetaBackend *backend)
|
||||
G_CALLBACK (on_device_added), backend, 0);
|
||||
|
||||
META_BACKEND_CLASS (meta_backend_x11_parent_class)->post_init (backend);
|
||||
|
||||
monitor_manager = meta_backend_get_monitor_manager (backend);
|
||||
g_signal_connect (monitor_manager, "monitors-changed",
|
||||
G_CALLBACK (on_monitors_changed), backend);
|
||||
}
|
||||
|
||||
static ClutterBackend *
|
||||
@ -622,6 +640,29 @@ meta_backend_x11_warp_pointer (MetaBackend *backend,
|
||||
x, y);
|
||||
}
|
||||
|
||||
static MetaLogicalMonitor *
|
||||
meta_backend_x11_get_current_logical_monitor (MetaBackend *backend)
|
||||
{
|
||||
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
|
||||
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
|
||||
MetaCursorTracker *cursor_tracker;
|
||||
int x, y;
|
||||
MetaMonitorManager *monitor_manager;
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
if (priv->cached_current_logical_monitor)
|
||||
return priv->cached_current_logical_monitor;
|
||||
|
||||
cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
||||
meta_cursor_tracker_get_pointer (cursor_tracker, &x, &y, NULL);
|
||||
monitor_manager = meta_backend_get_monitor_manager (backend);
|
||||
logical_monitor =
|
||||
meta_monitor_manager_get_logical_monitor_at (monitor_manager, x, y);
|
||||
|
||||
priv->cached_current_logical_monitor = logical_monitor;
|
||||
return priv->cached_current_logical_monitor;
|
||||
}
|
||||
|
||||
static void
|
||||
get_xkbrf_var_defs (Display *xdisplay,
|
||||
const char *layouts,
|
||||
@ -811,6 +852,14 @@ meta_backend_x11_set_numlock (MetaBackend *backend,
|
||||
/* TODO: Currently handled by gnome-settings-deamon */
|
||||
}
|
||||
|
||||
void
|
||||
meta_backend_x11_handle_event (MetaBackendX11 *x11,
|
||||
XEvent *xevent)
|
||||
{
|
||||
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
|
||||
|
||||
priv->cached_current_logical_monitor = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_backend_x11_update_screen_size (MetaBackend *backend,
|
||||
@ -899,6 +948,7 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
|
||||
backend_class->grab_device = meta_backend_x11_grab_device;
|
||||
backend_class->ungrab_device = meta_backend_x11_ungrab_device;
|
||||
backend_class->warp_pointer = meta_backend_x11_warp_pointer;
|
||||
backend_class->get_current_logical_monitor = meta_backend_x11_get_current_logical_monitor;
|
||||
backend_class->set_keymap = meta_backend_x11_set_keymap;
|
||||
backend_class->get_keymap = meta_backend_x11_get_keymap;
|
||||
backend_class->lock_layout_group = meta_backend_x11_lock_layout_group;
|
||||
|
@ -39,4 +39,7 @@ Display * meta_backend_x11_get_xdisplay (MetaBackendX11 *backend);
|
||||
|
||||
Window meta_backend_x11_get_xwindow (MetaBackendX11 *backend);
|
||||
|
||||
void meta_backend_x11_handle_event (MetaBackendX11 *x11,
|
||||
XEvent *xevent);
|
||||
|
||||
#endif /* META_BACKEND_X11_H */
|
||||
|
@ -651,8 +651,6 @@ meta_display_open (void)
|
||||
display->leader_window = None;
|
||||
display->timestamp_pinging_window = None;
|
||||
|
||||
display->monitor_cache_invalidated = TRUE;
|
||||
|
||||
display->groups_by_leader = NULL;
|
||||
|
||||
display->screen = NULL;
|
||||
@ -3085,6 +3083,7 @@ meta_display_request_pad_osd (MetaDisplay *display,
|
||||
ClutterInputDevice *pad,
|
||||
gboolean edition_mode)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaInputSettings *input_settings;
|
||||
const gchar *layout_path = NULL;
|
||||
ClutterActor *osd;
|
||||
@ -3119,7 +3118,7 @@ meta_display_request_pad_osd (MetaDisplay *display,
|
||||
return;
|
||||
|
||||
if (!logical_monitor)
|
||||
logical_monitor = meta_screen_get_current_logical_monitor (display->screen);
|
||||
logical_monitor = meta_backend_get_current_logical_monitor (backend);
|
||||
|
||||
g_signal_emit (display, display_signals[SHOW_PAD_OSD], 0,
|
||||
pad, settings, layout_path,
|
||||
|
@ -81,6 +81,7 @@ find_next_cascade (MetaWindow *window,
|
||||
int *new_x,
|
||||
int *new_y)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
GList *tmp;
|
||||
GList *sorted;
|
||||
int cascade_x, cascade_y;
|
||||
@ -114,7 +115,7 @@ find_next_cascade (MetaWindow *window,
|
||||
* of NW corner of window frame.
|
||||
*/
|
||||
|
||||
current = meta_screen_get_current_logical_monitor (window->screen);
|
||||
current = meta_backend_get_current_logical_monitor (backend);
|
||||
meta_window_get_work_area_for_logical_monitor (window, current, &work_area);
|
||||
|
||||
cascade_x = MAX (0, work_area.x);
|
||||
@ -665,6 +666,7 @@ meta_window_place (MetaWindow *window,
|
||||
int *new_x,
|
||||
int *new_y)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
GList *windows = NULL;
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
@ -815,7 +817,7 @@ meta_window_place (MetaWindow *window,
|
||||
meta_window_get_frame_rect (window, &frame_rect);
|
||||
|
||||
/* Warning, this function is a round trip! */
|
||||
logical_monitor = meta_screen_get_current_logical_monitor (window->screen);
|
||||
logical_monitor = meta_backend_get_current_logical_monitor (backend);
|
||||
|
||||
w = logical_monitor->rect.width;
|
||||
h = logical_monitor->rect.height;
|
||||
@ -859,8 +861,8 @@ meta_window_place (MetaWindow *window,
|
||||
g_slist_free (all_windows);
|
||||
}
|
||||
|
||||
/* Warning, this is a round trip! */
|
||||
logical_monitor = meta_screen_get_current_logical_monitor (window->screen);
|
||||
/* Warning, on X11 this might be a round trip! */
|
||||
logical_monitor = meta_backend_get_current_logical_monitor (backend);
|
||||
|
||||
/* Maximize windows if they are too big for their work area (bit of
|
||||
* a hack here). Assume undecorated windows probably don't intend to
|
||||
|
@ -77,9 +77,6 @@ struct _MetaScreen
|
||||
|
||||
gboolean has_xinerama_indices;
|
||||
|
||||
/* Cache the current monitor */
|
||||
int last_monitor_index;
|
||||
|
||||
GSList *startup_sequences;
|
||||
|
||||
Window wm_cm_selection_window;
|
||||
@ -133,10 +130,6 @@ void meta_screen_hide_tile_preview (MetaScreen *screen);
|
||||
MetaWindow* meta_screen_get_mouse_window (MetaScreen *screen,
|
||||
MetaWindow *not_this_one);
|
||||
|
||||
MetaLogicalMonitor * meta_screen_get_current_logical_monitor (MetaScreen *screen);
|
||||
MetaLogicalMonitor * meta_screen_get_current_logical_monitor_for_pos (MetaScreen *screen,
|
||||
int x,
|
||||
int y);
|
||||
MetaLogicalMonitor * meta_screen_calculate_logical_monitor_for_window (MetaScreen *screen,
|
||||
MetaWindow *window);
|
||||
|
||||
|
@ -430,9 +430,7 @@ reload_logical_monitors (MetaScreen *screen)
|
||||
meta_workspace_invalidate_work_area (space);
|
||||
}
|
||||
|
||||
screen->last_monitor_index = 0;
|
||||
screen->has_xinerama_indices = FALSE;
|
||||
screen->display->monitor_cache_invalidated = TRUE;
|
||||
}
|
||||
|
||||
/* The guard window allows us to leave minimized windows mapped so
|
||||
@ -1488,97 +1486,6 @@ meta_screen_get_monitor_neighbor_index (MetaScreen *screen,
|
||||
return logical_monitor ? logical_monitor->number : -1;
|
||||
}
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_screen_get_current_logical_monitor (MetaScreen *screen)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitors;
|
||||
unsigned int n_logical_monitors;
|
||||
int monitor_index;
|
||||
|
||||
logical_monitors =
|
||||
meta_monitor_manager_get_logical_monitors (monitor_manager,
|
||||
&n_logical_monitors);
|
||||
monitor_index = meta_screen_get_current_monitor (screen);
|
||||
|
||||
return &logical_monitors[monitor_index];
|
||||
}
|
||||
|
||||
static int
|
||||
meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
MetaLogicalMonitor *
|
||||
meta_screen_get_current_logical_monitor_for_pos (MetaScreen *screen,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitors;
|
||||
unsigned int n_logical_monitors;
|
||||
int monitor_index;
|
||||
|
||||
logical_monitors =
|
||||
meta_monitor_manager_get_logical_monitors (monitor_manager,
|
||||
&n_logical_monitors);
|
||||
monitor_index = meta_screen_get_current_monitor_for_pos (screen, x, y);
|
||||
|
||||
return &logical_monitors[monitor_index];
|
||||
}
|
||||
|
||||
static int
|
||||
meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaLogicalMonitor *logical_monitors;
|
||||
unsigned int n_logical_monitors;
|
||||
|
||||
logical_monitors =
|
||||
meta_monitor_manager_get_logical_monitors (monitor_manager,
|
||||
&n_logical_monitors);
|
||||
|
||||
if (n_logical_monitors == 1)
|
||||
return 0;
|
||||
else if (screen->display->monitor_cache_invalidated)
|
||||
{
|
||||
unsigned int i;
|
||||
MetaRectangle pointer_position;
|
||||
pointer_position.x = x;
|
||||
pointer_position.y = y;
|
||||
pointer_position.width = pointer_position.height = 1;
|
||||
|
||||
screen->display->monitor_cache_invalidated = FALSE;
|
||||
screen->last_monitor_index = 0;
|
||||
|
||||
for (i = 0; i < n_logical_monitors; i++)
|
||||
{
|
||||
if (meta_rectangle_contains_rect (&logical_monitors[i].rect,
|
||||
&pointer_position))
|
||||
{
|
||||
screen->last_monitor_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
meta_topic (META_DEBUG_XINERAMA,
|
||||
"Rechecked current monitor, now %d\n",
|
||||
screen->last_monitor_index);
|
||||
|
||||
}
|
||||
|
||||
return screen->last_monitor_index;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* meta_screen_get_current_monitor:
|
||||
* @screen: a #MetaScreen
|
||||
@ -1591,27 +1498,15 @@ int
|
||||
meta_screen_get_current_monitor (MetaScreen *screen)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
MetaMonitorManager *monitor_manager =
|
||||
meta_backend_get_monitor_manager (backend);
|
||||
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
||||
int n_logical_monitors =
|
||||
meta_monitor_manager_get_num_logical_monitors (monitor_manager);
|
||||
MetaLogicalMonitor *logical_monitor;
|
||||
|
||||
if (n_logical_monitors == 1)
|
||||
logical_monitor = meta_backend_get_current_logical_monitor (backend);
|
||||
|
||||
/* Pretend its the first when there is no actual current monitor. */
|
||||
if (!logical_monitor)
|
||||
return 0;
|
||||
|
||||
/* Sadly, we have to do it this way. Yuck.
|
||||
*/
|
||||
|
||||
if (screen->display->monitor_cache_invalidated)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
meta_cursor_tracker_get_pointer (cursor_tracker, &x, &y, NULL);
|
||||
meta_screen_get_current_monitor_for_pos (screen, x, y);
|
||||
}
|
||||
|
||||
return screen->last_monitor_index;
|
||||
return logical_monitor->number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -729,6 +729,8 @@ void meta_window_activate_full (MetaWindow *window,
|
||||
MetaClientType source_indication,
|
||||
MetaWorkspace *workspace);
|
||||
|
||||
MetaLogicalMonitor * meta_window_calculate_main_logical_monitor (MetaWindow *window);
|
||||
|
||||
void meta_window_update_monitor (MetaWindow *window,
|
||||
gboolean user_op);
|
||||
|
||||
|
@ -28,11 +28,12 @@
|
||||
#include <X11/extensions/shape.h>
|
||||
|
||||
#include <meta/errors.h>
|
||||
#include "meta/meta-backend.h"
|
||||
#include "bell.h"
|
||||
#include "display-private.h"
|
||||
#include "window-private.h"
|
||||
#include "workspace-private.h"
|
||||
|
||||
#include "backends/x11/meta-backend-x11.h"
|
||||
#include "x11/window-x11.h"
|
||||
#include "x11/xprops.h"
|
||||
|
||||
@ -1697,6 +1698,7 @@ static gboolean
|
||||
meta_display_handle_xevent (MetaDisplay *display,
|
||||
XEvent *event)
|
||||
{
|
||||
MetaBackend *backend = meta_get_backend ();
|
||||
Window modified;
|
||||
gboolean bypass_compositor = FALSE, bypass_gtk = FALSE;
|
||||
XIEvent *input_event;
|
||||
@ -1722,7 +1724,9 @@ meta_display_handle_xevent (MetaDisplay *display,
|
||||
#endif
|
||||
|
||||
display->current_time = event_get_time (display, event);
|
||||
display->monitor_cache_invalidated = TRUE;
|
||||
|
||||
if (META_IS_BACKEND_X11 (backend))
|
||||
meta_backend_x11_handle_event (META_BACKEND_X11 (backend), event);
|
||||
|
||||
if (display->focused_by_us &&
|
||||
event->xany.serial > display->focus_serial &&
|
||||
|
Loading…
Reference in New Issue
Block a user