From 2101c8357ba117870bd33afebe5b810230e0845c Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 29 Apr 2014 16:59:54 -0400 Subject: [PATCH] Move sync_request_* handling mostly to window-x11 --- src/core/events.c | 2 +- src/core/window-private.h | 6 -- src/core/window.c | 136 ------------------------------------- src/x11/window-props.c | 4 +- src/x11/window-x11.c | 138 +++++++++++++++++++++++++++++++++++++- src/x11/window-x11.h | 5 ++ 6 files changed, 145 insertions(+), 146 deletions(-) diff --git a/src/core/events.c b/src/core/events.c index 0a5b872c8..385dd9298 100644 --- a/src/core/events.c +++ b/src/core/events.c @@ -1250,7 +1250,7 @@ handle_other_xevent (MetaDisplay *display, XSyncValue value = ((XSyncAlarmNotifyEvent*)event)->counter_value; gint64 new_counter_value; new_counter_value = XSyncValueLow32 (value) + ((gint64)XSyncValueHigh32 (value) << 32); - meta_window_update_sync_request_counter (alarm_window, new_counter_value); + meta_window_x11_update_sync_request_counter (alarm_window, new_counter_value); bypass_gtk = TRUE; /* GTK doesn't want to see this really */ } diff --git a/src/core/window-private.h b/src/core/window-private.h index fc673f64e..837ee5ead 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -629,9 +629,6 @@ void meta_window_show_menu (MetaWindow *window, int button, guint32 timestamp); -void meta_window_update_sync_request_counter (MetaWindow *window, - gint64 new_counter_value); - gboolean meta_window_handle_mouse_grab_op_event (MetaWindow *window, const ClutterEvent *event); @@ -656,9 +653,6 @@ gboolean meta_window_same_application (MetaWindow *window, void meta_window_free_delete_dialog (MetaWindow *window); -void meta_window_create_sync_request_alarm (MetaWindow *window); -void meta_window_destroy_sync_request_alarm (MetaWindow *window); - void meta_window_update_keyboard_resize (MetaWindow *window, gboolean update_cursor); void meta_window_update_keyboard_move (MetaWindow *window); diff --git a/src/core/window.c b/src/core/window.c index b6628c22e..901e4d462 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1607,8 +1607,6 @@ meta_window_unmanage (MetaWindow *window, if (!window->override_redirect) meta_stack_remove (window->screen->stack, window); - meta_window_destroy_sync_request_alarm (window); - /* If an undecorated window is being withdrawn, that will change the * stack as presented to the compositing manager, without actually * changing the stacking order of X windows. @@ -3932,89 +3930,6 @@ adjust_for_gravity (MetaWindow *window, } } -void -meta_window_create_sync_request_alarm (MetaWindow *window) -{ - XSyncAlarmAttributes values; - XSyncValue init; - - if (window->sync_request_counter == None || - window->sync_request_alarm != None) - return; - - meta_error_trap_push (window->display); - - /* In the new (extended style), the counter value is initialized by - * the client before mapping the window. In the old style, we're - * responsible for setting the initial value of the counter. - */ - if (window->extended_sync_request_counter) - { - if (!XSyncQueryCounter(window->display->xdisplay, - window->sync_request_counter, - &init)) - { - meta_error_trap_pop_with_return (window->display); - window->sync_request_counter = None; - return; - } - - window->sync_request_serial = - XSyncValueLow32 (init) + ((gint64)XSyncValueHigh32 (init) << 32); - } - else - { - XSyncIntToValue (&init, 0); - XSyncSetCounter (window->display->xdisplay, - window->sync_request_counter, init); - window->sync_request_serial = 0; - } - - values.trigger.counter = window->sync_request_counter; - values.trigger.test_type = XSyncPositiveComparison; - - /* Initialize to one greater than the current value */ - values.trigger.value_type = XSyncRelative; - XSyncIntToValue (&values.trigger.wait_value, 1); - - /* After triggering, increment test_value by this until - * until the test condition is false */ - XSyncIntToValue (&values.delta, 1); - - /* we want events (on by default anyway) */ - values.events = True; - - window->sync_request_alarm = XSyncCreateAlarm (window->display->xdisplay, - XSyncCACounter | - XSyncCAValueType | - XSyncCAValue | - XSyncCATestType | - XSyncCADelta | - XSyncCAEvents, - &values); - - if (meta_error_trap_pop_with_return (window->display) == Success) - meta_display_register_sync_alarm (window->display, &window->sync_request_alarm, window); - else - { - window->sync_request_alarm = None; - window->sync_request_counter = None; - } -} - -void -meta_window_destroy_sync_request_alarm (MetaWindow *window) -{ - if (window->sync_request_alarm != None) - { - /* Has to be unregistered _before_ clearing the structure field */ - meta_display_unregister_sync_alarm (window->display, window->sync_request_alarm); - XSyncDestroyAlarm (window->display->xdisplay, - window->sync_request_alarm); - window->sync_request_alarm = None; - } -} - /** * meta_window_updates_are_frozen: * @window: a #MetaWindow @@ -7012,57 +6927,6 @@ meta_window_update_resize (MetaWindow *window, update_resize (window, snap, x, y, force); } -void -meta_window_update_sync_request_counter (MetaWindow *window, - gint64 new_counter_value) -{ - gboolean needs_frame_drawn = FALSE; - gboolean no_delay_frame = FALSE; - - if (window->extended_sync_request_counter && new_counter_value % 2 == 0) - { - needs_frame_drawn = TRUE; - no_delay_frame = new_counter_value == window->sync_request_serial + 1; - } - - window->sync_request_serial = new_counter_value; - meta_compositor_set_updates_frozen (window->display->compositor, window, - meta_window_updates_are_frozen (window)); - - if (window == window->display->grab_window && - meta_grab_op_is_resizing (window->display->grab_op) && - new_counter_value >= window->sync_request_wait_serial && - (!window->extended_sync_request_counter || new_counter_value % 2 == 0) && - window->sync_request_timeout_id) - { - meta_topic (META_DEBUG_RESIZING, - "Alarm event received last motion x = %d y = %d\n", - window->display->grab_latest_motion_x, - window->display->grab_latest_motion_y); - - g_source_remove (window->sync_request_timeout_id); - window->sync_request_timeout_id = 0; - - /* This means we are ready for another configure; - * no pointer round trip here, to keep in sync */ - update_resize (window, - window->display->grab_last_user_action_was_snap, - window->display->grab_latest_motion_x, - window->display->grab_latest_motion_y, - TRUE); - } - - /* If sync was previously disabled, turn it back on and hope - * the application has come to its senses (maybe it was just - * busy with a pagefault or a long computation). - */ - window->disable_sync = FALSE; - - if (needs_frame_drawn) - meta_compositor_queue_frame_drawn (window->display->compositor, window, - no_delay_frame); -} - static void end_grab_op (MetaWindow *window, const ClutterEvent *event) diff --git a/src/x11/window-props.c b/src/x11/window-props.c index f37bb1088..cb0a07800 100644 --- a/src/x11/window-props.c +++ b/src/x11/window-props.c @@ -897,7 +897,7 @@ reload_update_counter (MetaWindow *window, { if (value->type != META_PROP_VALUE_INVALID) { - meta_window_destroy_sync_request_alarm (window); + meta_window_x11_destroy_sync_request_alarm (window); window->sync_request_counter = None; if (value->v.xcounter_list.n_counters == 0) @@ -921,7 +921,7 @@ reload_update_counter (MetaWindow *window, window->extended_sync_request_counter ? "true" : "false"); if (window->extended_sync_request_counter) - meta_window_create_sync_request_alarm (window); + meta_window_x11_create_sync_request_alarm (window); } } diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 21fb1e18c..a492b6883 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -275,6 +275,8 @@ meta_window_x11_unmanage (MetaWindow *window) { meta_error_trap_push (window->display); + meta_window_x11_destroy_sync_request_alarm (window); + if (window->withdrawn) { /* We need to clean off the window's state so it @@ -528,7 +530,7 @@ meta_window_x11_grab_op_began (MetaWindow *window, if (meta_grab_op_is_resizing (op)) { if (window->sync_request_counter != None) - meta_window_create_sync_request_alarm (window); + meta_window_x11_create_sync_request_alarm (window); if (window->size_hints.width_inc > 1 || window->size_hints.height_inc > 1) { @@ -2989,3 +2991,137 @@ meta_window_x11_set_allowed_actions_hint (MetaWindow *window) meta_error_trap_pop (window->display); #undef MAX_N_ACTIONS } + +void +meta_window_x11_create_sync_request_alarm (MetaWindow *window) +{ + XSyncAlarmAttributes values; + XSyncValue init; + + if (window->sync_request_counter == None || + window->sync_request_alarm != None) + return; + + meta_error_trap_push (window->display); + + /* In the new (extended style), the counter value is initialized by + * the client before mapping the window. In the old style, we're + * responsible for setting the initial value of the counter. + */ + if (window->extended_sync_request_counter) + { + if (!XSyncQueryCounter(window->display->xdisplay, + window->sync_request_counter, + &init)) + { + meta_error_trap_pop_with_return (window->display); + window->sync_request_counter = None; + return; + } + + window->sync_request_serial = + XSyncValueLow32 (init) + ((gint64)XSyncValueHigh32 (init) << 32); + } + else + { + XSyncIntToValue (&init, 0); + XSyncSetCounter (window->display->xdisplay, + window->sync_request_counter, init); + window->sync_request_serial = 0; + } + + values.trigger.counter = window->sync_request_counter; + values.trigger.test_type = XSyncPositiveComparison; + + /* Initialize to one greater than the current value */ + values.trigger.value_type = XSyncRelative; + XSyncIntToValue (&values.trigger.wait_value, 1); + + /* After triggering, increment test_value by this until + * until the test condition is false */ + XSyncIntToValue (&values.delta, 1); + + /* we want events (on by default anyway) */ + values.events = True; + + window->sync_request_alarm = XSyncCreateAlarm (window->display->xdisplay, + XSyncCACounter | + XSyncCAValueType | + XSyncCAValue | + XSyncCATestType | + XSyncCADelta | + XSyncCAEvents, + &values); + + if (meta_error_trap_pop_with_return (window->display) == Success) + meta_display_register_sync_alarm (window->display, &window->sync_request_alarm, window); + else + { + window->sync_request_alarm = None; + window->sync_request_counter = None; + } +} + +void +meta_window_x11_destroy_sync_request_alarm (MetaWindow *window) +{ + if (window->sync_request_alarm != None) + { + /* Has to be unregistered _before_ clearing the structure field */ + meta_display_unregister_sync_alarm (window->display, window->sync_request_alarm); + XSyncDestroyAlarm (window->display->xdisplay, + window->sync_request_alarm); + window->sync_request_alarm = None; + } +} + +void +meta_window_x11_update_sync_request_counter (MetaWindow *window, + gint64 new_counter_value) +{ + gboolean needs_frame_drawn = FALSE; + gboolean no_delay_frame = FALSE; + + if (window->extended_sync_request_counter && new_counter_value % 2 == 0) + { + needs_frame_drawn = TRUE; + no_delay_frame = new_counter_value == window->sync_request_serial + 1; + } + + window->sync_request_serial = new_counter_value; + meta_compositor_set_updates_frozen (window->display->compositor, window, + meta_window_updates_are_frozen (window)); + + if (window == window->display->grab_window && + meta_grab_op_is_resizing (window->display->grab_op) && + new_counter_value >= window->sync_request_wait_serial && + (!window->extended_sync_request_counter || new_counter_value % 2 == 0) && + window->sync_request_timeout_id) + { + meta_topic (META_DEBUG_RESIZING, + "Alarm event received last motion x = %d y = %d\n", + window->display->grab_latest_motion_x, + window->display->grab_latest_motion_y); + + g_source_remove (window->sync_request_timeout_id); + window->sync_request_timeout_id = 0; + + /* This means we are ready for another configure; + * no pointer round trip here, to keep in sync */ + meta_window_update_resize (window, + window->display->grab_last_user_action_was_snap, + window->display->grab_latest_motion_x, + window->display->grab_latest_motion_y, + TRUE); + } + + /* If sync was previously disabled, turn it back on and hope + * the application has come to its senses (maybe it was just + * busy with a pagefault or a long computation). + */ + window->disable_sync = FALSE; + + if (needs_frame_drawn) + meta_compositor_queue_frame_drawn (window->display->compositor, window, + no_delay_frame); +} diff --git a/src/x11/window-x11.h b/src/x11/window-x11.h index 5c4002482..8bda6c7b6 100644 --- a/src/x11/window-x11.h +++ b/src/x11/window-x11.h @@ -44,6 +44,11 @@ void meta_window_x11_set_net_wm_state (MetaWindow *window); void meta_window_x11_set_wm_state (MetaWindow *window); void meta_window_x11_set_allowed_actions_hint (MetaWindow *window); +void meta_window_x11_create_sync_request_alarm (MetaWindow *window); +void meta_window_x11_destroy_sync_request_alarm (MetaWindow *window); +void meta_window_x11_update_sync_request_counter (MetaWindow *window, + gint64 new_counter_value); + void meta_window_x11_update_role (MetaWindow *window); void meta_window_x11_update_net_wm_type (MetaWindow *window); void meta_window_x11_update_opaque_region (MetaWindow *window);