mirror of
https://github.com/brl/mutter.git
synced 2024-11-27 18:40:40 -05:00
ui: Use input-events.h to translate XEvents to GdkEvents
This is the only use in the UI part of core functions not exported via core.h, but this is sort of a hack within a hack, and still better than doing the XInput2 vs core dance again.
This commit is contained in:
parent
49dfb40b82
commit
d664579115
97
src/ui/ui.c
97
src/ui/ui.c
@ -30,6 +30,7 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "theme-private.h"
|
#include "theme-private.h"
|
||||||
|
#include "input-events.h"
|
||||||
|
|
||||||
#include "inlinepixbufs.h"
|
#include "inlinepixbufs.h"
|
||||||
|
|
||||||
@ -102,27 +103,30 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
{
|
{
|
||||||
GdkDisplay *gdisplay;
|
GdkDisplay *gdisplay;
|
||||||
GdkDeviceManager *gmanager;
|
GdkDeviceManager *gmanager;
|
||||||
|
GdkDevice *gdevice;
|
||||||
MetaUI *ui;
|
MetaUI *ui;
|
||||||
GdkEvent *gevent;
|
GdkEvent *gevent;
|
||||||
GdkWindow *gdk_window;
|
GdkWindow *gdk_window;
|
||||||
Window window;
|
Window window;
|
||||||
|
MetaDisplay *display;
|
||||||
|
MetaDevice *device;
|
||||||
|
gdouble x, y, x_root, y_root;
|
||||||
|
guint evtype, n_button;
|
||||||
|
Time evtime;
|
||||||
|
|
||||||
switch (xevent->type)
|
display = meta_display_for_x_display (xevent->xany.display);
|
||||||
{
|
|
||||||
case ButtonPress:
|
if (!meta_input_event_get_type (display, xevent, &evtype))
|
||||||
case ButtonRelease:
|
return FALSE;
|
||||||
window = xevent->xbutton.window;
|
|
||||||
break;
|
if (evtype != ButtonPress &&
|
||||||
case MotionNotify:
|
evtype != ButtonRelease &&
|
||||||
window = xevent->xmotion.window;
|
evtype != EnterNotify &&
|
||||||
break;
|
evtype != LeaveNotify &&
|
||||||
case EnterNotify:
|
evtype != MotionNotify)
|
||||||
case LeaveNotify:
|
return FALSE;
|
||||||
window = xevent->xcrossing.window;
|
|
||||||
break;
|
window = meta_input_event_get_window (display, xevent);
|
||||||
default:
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gdisplay = gdk_x11_lookup_xdisplay (xevent->xany.display);
|
gdisplay = gdk_x11_lookup_xdisplay (xevent->xany.display);
|
||||||
ui = g_object_get_data (G_OBJECT (gdisplay), "meta-ui");
|
ui = g_object_get_data (G_OBJECT (gdisplay), "meta-ui");
|
||||||
@ -133,18 +137,32 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
if (gdk_window == NULL)
|
if (gdk_window == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
device = meta_input_event_get_device (display, xevent);
|
||||||
|
|
||||||
|
if (!device)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
gmanager = gdk_display_get_device_manager (gdisplay);
|
||||||
|
gdevice = gdk_x11_device_manager_lookup (gmanager,
|
||||||
|
meta_device_get_id (device));
|
||||||
|
|
||||||
/* If GDK already thinks it has a grab, we better let it see events; this
|
/* If GDK already thinks it has a grab, we better let it see events; this
|
||||||
* is the menu-navigation case and events need to get sent to the appropriate
|
* is the menu-navigation case and events need to get sent to the appropriate
|
||||||
* (client-side) subwindow for individual menu items.
|
* (client-side) subwindow for individual menu items.
|
||||||
*/
|
*/
|
||||||
if (gdk_display_pointer_is_grabbed (gdisplay))
|
if (gdk_display_device_is_grabbed (gdisplay, gdevice))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
switch (xevent->type)
|
evtime = meta_input_event_get_time (display, xevent);
|
||||||
|
meta_input_event_get_coordinates (display, xevent,
|
||||||
|
&x, &y, &x_root, &y_root);
|
||||||
|
switch (evtype)
|
||||||
{
|
{
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
if (xevent->type == ButtonPress)
|
meta_input_event_get_button (display, xevent, &n_button);
|
||||||
|
|
||||||
|
if (evtype == ButtonPress)
|
||||||
{
|
{
|
||||||
GtkSettings *settings = gtk_settings_get_default ();
|
GtkSettings *settings = gtk_settings_get_default ();
|
||||||
int double_click_time;
|
int double_click_time;
|
||||||
@ -155,11 +173,11 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
"gtk-double-click-distance", &double_click_distance,
|
"gtk-double-click-distance", &double_click_distance,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (xevent->xbutton.button == ui->button_click_number &&
|
if (n_button == ui->button_click_number &&
|
||||||
xevent->xbutton.window == ui->button_click_window &&
|
window == ui->button_click_window &&
|
||||||
xevent->xbutton.time < ui->button_click_time + double_click_time &&
|
evtime < ui->button_click_time + double_click_time &&
|
||||||
ABS (xevent->xbutton.x - ui->button_click_x) <= double_click_distance &&
|
ABS ((int) x - ui->button_click_x) <= double_click_distance &&
|
||||||
ABS (xevent->xbutton.y - ui->button_click_y) <= double_click_distance)
|
ABS ((int) y - ui->button_click_y) <= double_click_distance)
|
||||||
{
|
{
|
||||||
gevent = gdk_event_new (GDK_2BUTTON_PRESS);
|
gevent = gdk_event_new (GDK_2BUTTON_PRESS);
|
||||||
|
|
||||||
@ -168,11 +186,11 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
gevent = gdk_event_new (GDK_BUTTON_PRESS);
|
gevent = gdk_event_new (GDK_BUTTON_PRESS);
|
||||||
ui->button_click_number = xevent->xbutton.button;
|
ui->button_click_number = n_button;
|
||||||
ui->button_click_window = xevent->xbutton.window;
|
ui->button_click_window = window;
|
||||||
ui->button_click_time = xevent->xbutton.time;
|
ui->button_click_time = evtime;
|
||||||
ui->button_click_x = xevent->xbutton.x;
|
ui->button_click_x = (int) x;
|
||||||
ui->button_click_y = xevent->xbutton.y;
|
ui->button_click_y = (int) y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -181,12 +199,12 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gevent->button.window = g_object_ref (gdk_window);
|
gevent->button.window = g_object_ref (gdk_window);
|
||||||
gevent->button.button = xevent->xbutton.button;
|
gevent->button.button = n_button;
|
||||||
gevent->button.time = xevent->xbutton.time;
|
gevent->button.time = evtime;
|
||||||
gevent->button.x = xevent->xbutton.x;
|
gevent->button.x = x;
|
||||||
gevent->button.y = xevent->xbutton.y;
|
gevent->button.y = y;
|
||||||
gevent->button.x_root = xevent->xbutton.x_root;
|
gevent->button.x_root = x_root;
|
||||||
gevent->button.y_root = xevent->xbutton.y_root;
|
gevent->button.y_root = y_root;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
@ -196,10 +214,10 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
break;
|
break;
|
||||||
case EnterNotify:
|
case EnterNotify:
|
||||||
case LeaveNotify:
|
case LeaveNotify:
|
||||||
gevent = gdk_event_new (xevent->type == EnterNotify ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY);
|
gevent = gdk_event_new (evtype == EnterNotify ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY);
|
||||||
gevent->crossing.window = g_object_ref (gdk_window);
|
gevent->crossing.window = g_object_ref (gdk_window);
|
||||||
gevent->crossing.x = xevent->xcrossing.x;
|
gevent->crossing.x = x;
|
||||||
gevent->crossing.y = xevent->xcrossing.y;
|
gevent->crossing.y = y;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
@ -207,8 +225,7 @@ maybe_redirect_mouse_event (XEvent *xevent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If we've gotten here, we've created the gdk_event and should send it on */
|
/* If we've gotten here, we've created the gdk_event and should send it on */
|
||||||
gmanager = gdk_display_get_device_manager (gdisplay);
|
gdk_event_set_device (gevent, gdevice);
|
||||||
gdk_event_set_device (gevent, gdk_device_manager_get_client_pointer (gmanager));
|
|
||||||
gtk_main_do_event (gevent);
|
gtk_main_do_event (gevent);
|
||||||
gdk_event_free (gevent);
|
gdk_event_free (gevent);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user