@@ -1,5 +1,3 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/* Marco X display handler */

/*
@@ -28,7 +26,7 @@
#define META_DISPLAY_PRIVATE_H

#ifndef PACKAGE
#error "config.h not included"
#error "config.h not included"
#endif

#include <glib.h>
@@ -39,11 +37,11 @@
#include "display.h"

#ifdef HAVE_STARTUP_NOTIFICATION
#include <libsn/sn.h>
#include <libsn/sn.h>
#endif

#ifdef HAVE_XSYNC
#include <X11/extensions/sync.h>
#include <X11/extensions/sync.h>
#endif

typedef struct _MetaKeyBinding MetaKeyBinding;
@@ -55,10 +53,7 @@ typedef struct _MetaGroupPropHooks MetaGroupPropHooks;

typedef struct MetaEdgeResistanceData MetaEdgeResistanceData;

typedef void (* MetaWindowPingFunc) (MetaDisplay *display,
Window xwindow,
guint32 timestamp,
gpointer user_data);
typedef void (*MetaWindowPingFunc) (MetaDisplay* display, Window xwindow, guint32 timestamp, gpointer user_data);


#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
@@ -72,236 +67,247 @@ typedef void (* MetaWindowPingFunc) (MetaDisplay *display,
*/
#define N_IGNORED_SERIALS 4

struct _MetaDisplay
{
char *name;
Display *xdisplay;

Window leader_window;
Window timestamp_pinging_window;

/* Pull in all the names of atoms as fields; we will intern them when the
* class is constructed.
*/
#define item(x) Atom atom_##x;
#include "atomnames.h"
#undef item

/* This is the actual window from focus events,
* not the one we last set
*/
MetaWindow *focus_window;

/* window we are expecting a FocusIn event for or the current focus
* window if we are not expecting any FocusIn/FocusOut events; not
* perfect because applications can call XSetInputFocus directly.
* (It could also be messed up if a timestamp later than current
* time is sent to meta_display_set_input_focus_window, though that
* would be a programming error). See bug 154598 for more info.
*/
MetaWindow *expected_focus_window;

/* last timestamp passed to XSetInputFocus */
guint32 last_focus_time;

/* last user interaction time in any app */
guint32 last_user_time;

/* whether we're using mousenav (only relevant for sloppy&mouse focus modes;
* !mouse_mode means "keynav mode")
*/
guint mouse_mode : 1;

/* Helper var used when focus_new_windows setting is 'strict'; only
* relevant in 'strict' mode and if the focus window is a terminal.
* In that case, we don't allow new windows to take focus away from
* a terminal, but if the user explicitly did something that should
* allow a different window to gain focus (e.g. global keybinding or
* clicking on a dock), then we will allow the transfer.
*/
guint allow_terminal_deactivation : 1;

guint static_gravity_works : 1;

/*< private-ish >*/
guint error_trap_synced_at_last_pop : 1;
MetaEventQueue *events;
GSList *screens;
MetaScreen *active_screen;
GHashTable *window_ids;
int error_traps;
int (* error_trap_handler) (Display *display,
XErrorEvent *error);
int server_grab_count;

/* serials of leave/unmap events that may
* correspond to an enter event we should
* ignore
*/
unsigned long ignored_serials[N_IGNORED_SERIALS];
Window ungrab_should_not_cause_focus_window;

guint32 current_time;

/* Pings which we're waiting for a reply from */
GSList *pending_pings;

/* Pending autoraise */
guint autoraise_timeout_id;
MetaWindow* autoraise_window;

/* Alt+click button grabs */
unsigned int window_grab_modifiers;
struct _MetaDisplay {
char* name;
Display* xdisplay;

Window leader_window;
Window timestamp_pinging_window;

/* Pull in all the names of atoms as fields; we will intern them when the
* class is constructed.
*/
#define item(x) Atom atom_##x;
#include "atomnames.h"
#undef item

/* This is the actual window from focus events,
* not the one we last set
*/
MetaWindow* focus_window;

/* window we are expecting a FocusIn event for or the current focus
* window if we are not expecting any FocusIn/FocusOut events; not
* perfect because applications can call XSetInputFocus directly.
* (It could also be messed up if a timestamp later than current
* time is sent to meta_display_set_input_focus_window, though that
* would be a programming error). See bug 154598 for more info.
*/
MetaWindow* expected_focus_window;

/* last timestamp passed to XSetInputFocus */
guint32 last_focus_time;

/* last user interaction time in any app */
guint32 last_user_time;

/* whether we're using mousenav (only relevant for sloppy&mouse focus modes;
* !mouse_mode means "keynav mode")
*/
guint mouse_mode: 1;

/* Helper var used when focus_new_windows setting is 'strict'; only
* relevant in 'strict' mode and if the focus window is a terminal.
* In that case, we don't allow new windows to take focus away from
* a terminal, but if the user explicitly did something that should
* allow a different window to gain focus (e.g. global keybinding or
* clicking on a dock), then we will allow the transfer.
*/
guint allow_terminal_deactivation: 1;

guint static_gravity_works: 1;

/*< private-ish >*/
guint error_trap_synced_at_last_pop: 1;
MetaEventQueue* events;
GSList* screens;
MetaScreen* active_screen;
GHashTable* window_ids;
int error_traps;
int (*error_trap_handler) (Display* display, XErrorEvent* error);
int server_grab_count;

/* serials of leave/unmap events that may
* correspond to an enter event we should
* ignore
*/
unsigned long ignored_serials[N_IGNORED_SERIALS];
Window ungrab_should_not_cause_focus_window;

/* current window operation */
MetaGrabOp grab_op;
MetaScreen *grab_screen;
MetaWindow *grab_window;
Window grab_xwindow;
int grab_button;
int grab_anchor_root_x;
int grab_anchor_root_y;
MetaRectangle grab_anchor_window_pos;
int grab_latest_motion_x;
int grab_latest_motion_y;
gulong grab_mask;
guint grab_have_pointer : 1;
guint grab_have_keyboard : 1;
guint grab_wireframe_active : 1;
guint grab_was_cancelled : 1; /* Only used in wireframe mode */
guint grab_frame_action : 1;
MetaRectangle grab_wireframe_rect;
MetaRectangle grab_wireframe_last_xor_rect;
MetaRectangle grab_initial_window_pos;
int grab_initial_x, grab_initial_y; /* These are only relevant for */
gboolean grab_threshold_movement_reached; /* raise_on_click == FALSE. */
MetaResizePopup *grab_resize_popup;
GTimeVal grab_last_moveresize_time;
guint32 grab_motion_notify_time;
int grab_wireframe_last_display_width;
int grab_wireframe_last_display_height;
GList* grab_old_window_stacking;
MetaEdgeResistanceData *grab_edge_resistance_data;
unsigned int grab_last_user_action_was_snap;

/* we use property updates as sentinels for certain window focus events
* to avoid some race conditions on EnterNotify events
*/
int sentinel_counter;

#ifdef HAVE_XKB
int xkb_base_event_type;
guint32 last_bell_time;
#endif
#ifdef HAVE_XSYNC
/* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
XSyncAlarm grab_sync_request_alarm;
#endif
int grab_resize_timeout_id;

/* Keybindings stuff */
MetaKeyBinding *key_bindings;
int n_key_bindings;
int min_keycode;
int max_keycode;
KeySym *keymap;
int keysyms_per_keycode;
XModifierKeymap *modmap;
unsigned int ignored_modifier_mask;
unsigned int num_lock_mask;
unsigned int scroll_lock_mask;
unsigned int hyper_mask;
unsigned int super_mask;
unsigned int meta_mask;

/* Xinerama cache */
unsigned int xinerama_cache_invalidated : 1;

/* Opening the display */
unsigned int display_opening : 1;

/* Closing down the display */
int closing;

/* To detect double clicks */
guint button_click_number;
Window button_click_window;
int button_click_x;
int button_click_y;
guint32 button_click_time;

/* Managed by group.c */
GHashTable *groups_by_leader;

/* currently-active window menu if any */
MetaWindowMenu *window_menu;
MetaWindow *window_with_menu;

/* Managed by window-props.c */
gpointer *prop_hooks_table;
GHashTable *prop_hooks;

/* Managed by group-props.c */
MetaGroupPropHooks *group_prop_hooks;

/* Managed by compositor.c */
MetaCompositor *compositor;
guint32 current_time;

/* Pings which we're waiting for a reply from */
GSList* pending_pings;

/* Pending autoraise */
guint autoraise_timeout_id;
MetaWindow* autoraise_window;

/* Alt+click button grabs */
unsigned int window_grab_modifiers;

/* current window operation */
MetaGrabOp grab_op;
MetaScreen* grab_screen;
MetaWindow* grab_window;
Window grab_xwindow;
int grab_button;
int grab_anchor_root_x;
int grab_anchor_root_y;
MetaRectangle grab_anchor_window_pos;
int grab_latest_motion_x;
int grab_latest_motion_y;
gulong grab_mask;
guint grab_have_pointer : 1;
guint grab_have_keyboard : 1;
guint grab_wireframe_active : 1;
guint grab_was_cancelled : 1; /* Only used in wireframe mode */
guint grab_frame_action : 1;
MetaRectangle grab_wireframe_rect;
MetaRectangle grab_wireframe_last_xor_rect;
MetaRectangle grab_initial_window_pos;
int grab_initial_x, grab_initial_y; /* These are only relevant for */
gboolean grab_threshold_movement_reached; /* raise_on_click == FALSE. */
MetaResizePopup* grab_resize_popup;
GTimeVal grab_last_moveresize_time;
guint32 grab_motion_notify_time;
int grab_wireframe_last_display_width;
int grab_wireframe_last_display_height;
GList* grab_old_window_stacking;
MetaEdgeResistanceData* grab_edge_resistance_data;
unsigned int grab_last_user_action_was_snap;

/* we use property updates as sentinels for certain window focus events
* to avoid some race conditions on EnterNotify events
*/
int sentinel_counter;

#ifdef HAVE_XKB
int xkb_base_event_type;
guint32 last_bell_time;
#endif

#ifdef HAVE_XSYNC
/* alarm monitoring client's _NET_WM_SYNC_REQUEST_COUNTER */
XSyncAlarm grab_sync_request_alarm;
#endif

int grab_resize_timeout_id;

/* Keybindings stuff */
MetaKeyBinding* key_bindings;
int n_key_bindings;
int min_keycode;
int max_keycode;
KeySym* keymap;
int keysyms_per_keycode;
XModifierKeymap* modmap;
unsigned int ignored_modifier_mask;
unsigned int num_lock_mask;
unsigned int scroll_lock_mask;
unsigned int hyper_mask;
unsigned int super_mask;
unsigned int meta_mask;

/* Xinerama cache */
unsigned int xinerama_cache_invalidated: 1;

/* Opening the display */
unsigned int display_opening: 1;

/* Closing down the display */
int closing;

/* To detect double clicks
*
* https://github.com/stefano-k/Mate-Desktop-Environment/commit/b0e5fb03eb21dae8f02692f11ef391bfc5ccba33
*/
guint button_click_number;
Window button_click_window;
int button_click_x;
int button_click_y;
guint32 button_click_time;

/* Managed by group.c */
GHashTable* groups_by_leader;

/* currently-active window menu if any */
MetaWindowMenu* window_menu;
MetaWindow* window_with_menu;

/* Managed by window-props.c */
gpointer* prop_hooks_table;
GHashTable* prop_hooks;

/* Managed by group-props.c */
MetaGroupPropHooks* group_prop_hooks;

/* Managed by compositor.c */
MetaCompositor* compositor;

#ifdef HAVE_STARTUP_NOTIFICATION
SnDisplay *sn_display;
#endif
#ifdef HAVE_XSYNC
int xsync_event_base;
int xsync_error_base;
#endif
#ifdef HAVE_SHAPE
int shape_event_base;
int shape_error_base;
#endif
#ifdef HAVE_RENDER
int render_event_base;
int render_error_base;
#endif
#ifdef HAVE_COMPOSITE_EXTENSIONS
int composite_event_base;
int composite_error_base;
int composite_major_version;
int composite_minor_version;
int damage_event_base;
int damage_error_base;
int xfixes_event_base;
int xfixes_error_base;
#endif
#ifdef HAVE_XSYNC
unsigned int have_xsync : 1;
#define META_DISPLAY_HAS_XSYNC(display) ((display)->have_xsync)
#else
#define META_DISPLAY_HAS_XSYNC(display) FALSE
#endif
#ifdef HAVE_SHAPE
unsigned int have_shape : 1;
#define META_DISPLAY_HAS_SHAPE(display) ((display)->have_shape)
#else
#define META_DISPLAY_HAS_SHAPE(display) FALSE
#endif
#ifdef HAVE_RENDER
unsigned int have_render : 1;
#define META_DISPLAY_HAS_RENDER(display) ((display)->have_render)
#else
#define META_DISPLAY_HAS_RENDER(display) FALSE
#endif
#ifdef HAVE_COMPOSITE_EXTENSIONS
unsigned int have_composite : 1;
unsigned int have_damage : 1;
unsigned int have_xfixes : 1;
#define META_DISPLAY_HAS_COMPOSITE(display) ((display)->have_composite)
#define META_DISPLAY_HAS_DAMAGE(display) ((display)->have_damage)
#define META_DISPLAY_HAS_XFIXES(display) ((display)->have_xfixes)
#else
#define META_DISPLAY_HAS_COMPOSITE(display) FALSE
#define META_DISPLAY_HAS_DAMAGE(display) FALSE
#define META_DISPLAY_HAS_XFIXES(display) FALSE
#endif
#ifdef HAVE_STARTUP_NOTIFICATION
SnDisplay* sn_display;
#endif

#ifdef HAVE_XSYNC
int xsync_event_base;
int xsync_error_base;
#endif

#ifdef HAVE_SHAPE
int shape_event_base;
int shape_error_base;
#endif

#ifdef HAVE_RENDER
int render_event_base;
int render_error_base;
#endif

#ifdef HAVE_COMPOSITE_EXTENSIONS
int composite_event_base;
int composite_error_base;
int composite_major_version;
int composite_minor_version;
int damage_event_base;
int damage_error_base;
int xfixes_event_base;
int xfixes_error_base;
#endif

#ifdef HAVE_XSYNC
unsigned int have_xsync : 1;
#define META_DISPLAY_HAS_XSYNC(display) ((display)->have_xsync)
#else
#define META_DISPLAY_HAS_XSYNC(display) FALSE
#endif

#ifdef HAVE_SHAPE
unsigned int have_shape : 1;
#define META_DISPLAY_HAS_SHAPE(display) ((display)->have_shape)
#else
#define META_DISPLAY_HAS_SHAPE(display) FALSE
#endif

#ifdef HAVE_RENDER
unsigned int have_render : 1;
#define META_DISPLAY_HAS_RENDER(display) ((display)->have_render)
#else
#define META_DISPLAY_HAS_RENDER(display) FALSE
#endif

#ifdef HAVE_COMPOSITE_EXTENSIONS
unsigned int have_composite : 1;
unsigned int have_damage : 1;
unsigned int have_xfixes : 1;
#define META_DISPLAY_HAS_COMPOSITE(display) ((display)->have_composite)
#define META_DISPLAY_HAS_DAMAGE(display) ((display)->have_damage)
#define META_DISPLAY_HAS_XFIXES(display) ((display)->have_xfixes)
#else
#define META_DISPLAY_HAS_COMPOSITE(display) FALSE
#define META_DISPLAY_HAS_DAMAGE(display) FALSE
#define META_DISPLAY_HAS_XFIXES(display) FALSE
#endif
};

/* Xserver time can wraparound, thus comparing two timestamps needs to take
@@ -317,14 +323,14 @@ struct _MetaDisplay
* the result.
*/
#define XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) \
( (( (time1) < (time2) ) && ( (time2) - (time1) < ((guint32)-1)/2 )) || \
(( (time1) > (time2) ) && ( (time1) - (time2) > ((guint32)-1)/2 )) \
)
#define XSERVER_TIME_IS_BEFORE(time1, time2) \
( (time1) == 0 || \
(XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) && \
(time2) != 0) \
)
( (( (time1) < (time2) ) && ( (time2) - (time1) < ((guint32)-1)/2 )) || \
(( (time1) > (time2) ) && ( (time1) - (time2) > ((guint32)-1)/2 )) \
)
#define XSERVER_TIME_IS_BEFORE(time1, time2) \
( (time1) == 0 || \
(XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) && \
(time2) != 0) \
)

gboolean meta_display_open (void);
void meta_display_close (MetaDisplay *display,
@@ -504,4 +510,4 @@ void meta_display_queue_autoraise_callback (MetaDisplay *display,
MetaWindow *window);
void meta_display_remove_autoraise_callback (MetaDisplay *display);

#endif
#endif /* META_DISPLAY_PRIVATE_H */
@@ -1,5 +1,3 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/* Marco X display handler */

/*
@@ -50,33 +48,42 @@
#include "compositor.h"
#include <X11/Xatom.h>
#include <X11/cursorfont.h>

#ifdef HAVE_SOLARIS_XINERAMA
#include <X11/extensions/xinerama.h>
#include <X11/extensions/xinerama.h>
#endif

#ifdef HAVE_XFREE_XINERAMA
#include <X11/extensions/Xinerama.h>
#include <X11/extensions/Xinerama.h>
#endif

#ifdef HAVE_RANDR
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/Xrandr.h>
#endif

#ifdef HAVE_SHAPE
#include <X11/extensions/shape.h>
#include <X11/extensions/shape.h>
#endif

#ifdef HAVE_RENDER
#include <X11/extensions/Xrender.h>
#include <X11/extensions/Xrender.h>
#endif

#ifdef HAVE_XKB
#include <X11/XKBlib.h>
#include <X11/XKBlib.h>
#endif

#ifdef HAVE_XCURSOR
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xcursor/Xcursor.h>
#endif

#ifdef HAVE_COMPOSITE_EXTENSIONS
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h>
#include <gtk/gtk.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h>
#include <gtk/gtk.h>
#endif

#include <string.h>

#define GRAB_OP_IS_WINDOW_SWITCH(g) \
@@ -1410,120 +1417,135 @@ handle_net_restack_window (MetaDisplay* display,
* To reduce the amount of code, the only events fields filled out
* below are the ones that frames.c uses. If frames.c is modified to
* use more fields, more fields need to be filled out below.
*
* https://github.com/stefano-k/Mate-Desktop-Environment/commit/b0e5fb03eb21dae8f02692f11ef391bfc5ccba33
*/

static gboolean
maybe_send_event_to_gtk (MetaDisplay *display,
XEvent *xevent)
static gboolean maybe_send_event_to_gtk(MetaDisplay* display, XEvent* xevent)
{
/* We're always using the default display */
GdkDisplay *gdk_display = gdk_display_get_default ();
GdkEvent gdk_event;
GdkWindow *gdk_window;
Window window;
/* We're always using the default display */
GdkDisplay* gdk_display = gdk_display_get_default();
GdkEvent gdk_event;
GdkWindow* gdk_window;
Window window;

switch (xevent->type)
{
case ButtonPress:
case ButtonRelease:
window = xevent->xbutton.window;
break;
case MotionNotify:
window = xevent->xmotion.window;
break;
case EnterNotify:
case LeaveNotify:
window = xevent->xcrossing.window;
break;
default:
return FALSE;
}
switch (xevent->type)
{
case ButtonPress:
case ButtonRelease:
window = xevent->xbutton.window;
break;

gdk_window = gdk_window_lookup_for_display (gdk_display, window);
if (gdk_window == NULL)
return FALSE;
case MotionNotify:
window = xevent->xmotion.window;
break;

/* If GDK already things 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
* (client-side) subwindow for individual menu items.
*/
if (gdk_display_pointer_is_grabbed (gdk_display))
return FALSE;
case EnterNotify:

memset (&gdk_event, 0, sizeof (gdk_event));
case LeaveNotify:
window = xevent->xcrossing.window;
break;

switch (xevent->type)
{
case ButtonPress:
case ButtonRelease:
if (xevent->type == ButtonPress)
{
GtkSettings *settings = gtk_settings_get_default ();
int double_click_time;
int double_click_distance;

g_object_get (settings,
"gtk-double-click-time", &double_click_time,
"gtk-double-click-distance", &double_click_distance,
NULL);

if (xevent->xbutton.button == display->button_click_number &&
xevent->xbutton.window == display->button_click_window &&
xevent->xbutton.time < display->button_click_time + double_click_time &&
ABS (xevent->xbutton.x - display->button_click_x) <= double_click_distance &&
ABS (xevent->xbutton.y - display->button_click_y) <= double_click_distance)
{
gdk_event.button.type = GDK_2BUTTON_PRESS;
default:
return FALSE;
}

display->button_click_number = 0;
}
else
{
gdk_event.button.type = GDK_BUTTON_PRESS;
display->button_click_number = xevent->xbutton.button;
display->button_click_window = xevent->xbutton.window;
display->button_click_time = xevent->xbutton.time;
display->button_click_x = xevent->xbutton.x;
display->button_click_y = xevent->xbutton.y;
}
}
else
{
gdk_event.button.type = GDK_BUTTON_RELEASE;
}
gdk_window = gdk_window_lookup_for_display(gdk_display, window);

gdk_event.button.window = gdk_window;
gdk_event.button.button = xevent->xbutton.button;
gdk_event.button.time = xevent->xbutton.time;
gdk_event.button.x = xevent->xbutton.x;
gdk_event.button.y = xevent->xbutton.y;
gdk_event.button.x_root = xevent->xbutton.x_root;
gdk_event.button.y_root = xevent->xbutton.y_root;
if (gdk_window == NULL)
{
return FALSE;
}

break;
case MotionNotify:
gdk_event.motion.type = GDK_MOTION_NOTIFY;
gdk_event.motion.window = gdk_window;
break;
case EnterNotify:
case LeaveNotify:
gdk_event.crossing.type = xevent->type == EnterNotify ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY;
gdk_event.crossing.window = gdk_window;
gdk_event.crossing.x = xevent->xcrossing.x;
gdk_event.crossing.y = xevent->xcrossing.y;
break;
default:
g_assert_not_reached ();
break;
}
/* If GDK already things 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
* (client-side) subwindow for individual menu items.
*/

/* If we've gotten here, we've filled in the gdk_event and should send it on */
if (gdk_display_pointer_is_grabbed(gdk_display))
{
return FALSE;
}

gtk_main_do_event (&gdk_event);
memset(&gdk_event, 0, sizeof(gdk_event));

return TRUE;
}
switch (xevent->type)
{

case ButtonPress:

case ButtonRelease:

if (xevent->type == ButtonPress)
{
GtkSettings* settings = gtk_settings_get_default();

int double_click_time;
int double_click_distance;

g_object_get (settings,
"gtk-double-click-time", &double_click_time,
"gtk-double-click-distance", &double_click_distance,
NULL);

if (xevent->xbutton.button == display->button_click_number &&
xevent->xbutton.window == display->button_click_window &&
xevent->xbutton.time < display->button_click_time + double_click_time &&
ABS(xevent->xbutton.x - display->button_click_x) <= double_click_distance &&
ABS (xevent->xbutton.y - display->button_click_y) <= double_click_distance)
{

gdk_event.button.type = GDK_2BUTTON_PRESS;
display->button_click_number = 0;
}
else
{
gdk_event.button.type = GDK_BUTTON_PRESS;
display->button_click_number = xevent->xbutton.button;
display->button_click_window = xevent->xbutton.window;
display->button_click_time = xevent->xbutton.time;
display->button_click_x = xevent->xbutton.x;
display->button_click_y = xevent->xbutton.y;
}
}
else
{
gdk_event.button.type = GDK_BUTTON_RELEASE;
}

gdk_event.button.window = gdk_window;
gdk_event.button.button = xevent->xbutton.button;
gdk_event.button.time = xevent->xbutton.time;
gdk_event.button.x = xevent->xbutton.x;
gdk_event.button.y = xevent->xbutton.y;
gdk_event.button.x_root = xevent->xbutton.x_root;
gdk_event.button.y_root = xevent->xbutton.y_root;

break;

case MotionNotify:
gdk_event.motion.type = GDK_MOTION_NOTIFY;
gdk_event.motion.window = gdk_window;
break;

case EnterNotify:

case LeaveNotify:
gdk_event.crossing.type = xevent->type == EnterNotify ? GDK_ENTER_NOTIFY : GDK_LEAVE_NOTIFY;
gdk_event.crossing.window = gdk_window;
gdk_event.crossing.x = xevent->xcrossing.x;
gdk_event.crossing.y = xevent->xcrossing.y;
break;

default:
g_assert_not_reached();
break;
}

/* If we've gotten here, we've filled in the gdk_event and should send it on */
gtk_main_do_event(&gdk_event);
return TRUE;
}

/**
* This is the most important function in the whole program. It is the heart,
@@ -1540,9 +1562,7 @@ maybe_send_event_to_gtk (MetaDisplay *display,
*
* \ingroup main
*/
static gboolean
event_callback (XEvent *event,
gpointer data)
static gboolean event_callback(XEvent* event, gpointer data)
{
MetaWindow *window;
MetaWindow *property_for_window;
@@ -2526,18 +2546,21 @@ event_callback (XEvent *event,
break;
}

if (display->compositor)
{
meta_compositor_process_event (display->compositor,
event,
window);
}

if (maybe_send_event_to_gtk (display, event))
filter_out_event = TRUE;
if (display->compositor)
{
meta_compositor_process_event (display->compositor, event, window);
}

display->current_time = CurrentTime;
return filter_out_event;
/* generates event on wrong window.
* https://github.com/stefano-k/Mate-Desktop-Environment/commit/b0e5fb03eb21dae8f02692f11ef391bfc5ccba33
*/
if (maybe_send_event_to_gtk(display, event))
{
filter_out_event = TRUE;
}

display->current_time = CurrentTime;
return filter_out_event;
}

/* Return the window this has to do with, if any, rather