+ waiting_for_sync = 0;
+
+#ifdef SYNC
+ if (config_resize_redraw && !moving && obt_display_extension_sync &&
+ moveresize_client->sync_request && moveresize_client->sync_counter &&
+ !moveresize_client->not_responding)
+ {
+ /* Initialize values for the resize syncing, and create an alarm for
+ the client's xsync counter */
+
+ XSyncValue val;
+ XSyncAlarmAttributes aa;
+
+ /* set the counter to an initial value */
+ XSyncIntToValue(&val, 0);
+ XSyncSetCounter(obt_display, moveresize_client->sync_counter, val);
+
+ /* this will be incremented when we tell the client what we're
+ looking for */
+ moveresize_client->sync_counter_value = 0;
+
+ /* the next sequence we're waiting for with the alarm */
+ XSyncIntToValue(&val, 1);
+
+ /* set an alarm on the counter */
+ aa.trigger.counter = moveresize_client->sync_counter;
+ aa.trigger.wait_value = val;
+ aa.trigger.value_type = XSyncAbsolute;
+ aa.trigger.test_type = XSyncPositiveTransition;
+ aa.events = True;
+ XSyncIntToValue(&aa.delta, 1);
+ moveresize_alarm = XSyncCreateAlarm(obt_display,
+ XSyncCACounter |
+ XSyncCAValue |
+ XSyncCAValueType |
+ XSyncCATestType |
+ XSyncCADelta |
+ XSyncCAEvents,
+ &aa);
+ }
+#endif
+}
+
+void moveresize_end(gboolean cancel)
+{
+ ungrab_keyboard();
+ ungrab_pointer();
+
+ popup_hide(popup);
+
+ if (!moving) {
+#ifdef SYNC
+ /* turn off the alarm */
+ if (moveresize_alarm != None) {
+ XSyncDestroyAlarm(obt_display, moveresize_alarm);
+ moveresize_alarm = None;
+ }
+
+ if (sync_timer) g_source_remove(sync_timer);
+ sync_timer = 0;
+#endif
+ }
+
+ /* don't use client_move() here, use the same width/height as
+ we've been using during the move, otherwise we get different results
+ when moving maximized windows between monitors of different sizes !
+ */
+ client_configure(moveresize_client,
+ (cancel ? start_cx : cur_x),
+ (cancel ? start_cy : cur_y),
+ (cancel ? start_cw : cur_w),
+ (cancel ? start_ch : cur_h),
+ TRUE, TRUE, FALSE);
+
+ /* restore the client's maximized state. do this after putting the window
+ back in its original spot to minimize visible flicker */
+ if (cancel && (was_max_horz || was_max_vert)) {
+ const gboolean h = moveresize_client->max_horz;
+ const gboolean v = moveresize_client->max_vert;
+
+ client_maximize(moveresize_client, TRUE,
+ was_max_horz && was_max_vert ? 0 :
+ (was_max_horz ? 1 : 2));
+
+ /* replace the premax values with the ones we had saved if
+ the client doesn't have any already set */
+ if (was_max_horz && !h) {
+ moveresize_client->pre_max_area.x = pre_max_area.x;
+ moveresize_client->pre_max_area.width = pre_max_area.width;
+ }
+ if (was_max_vert && !v) {
+ moveresize_client->pre_max_area.y = pre_max_area.y;
+ moveresize_client->pre_max_area.height = pre_max_area.height;
+ }
+ }
+
+ /* dont edge warp after its ended */
+ cancel_edge_warp();
+
+ moveresize_in_progress = FALSE;
+ moveresize_client = NULL;
+}
+
+static void do_move(gboolean keyboard, gint keydist)
+{
+ gint resist;
+
+ if (keyboard) resist = keydist - 1; /* resist for one key press */
+ else resist = config_resist_win;
+ resist_move_windows(moveresize_client, resist, &cur_x, &cur_y);
+ if (!keyboard) resist = config_resist_edge;
+ resist_move_monitors(moveresize_client, resist, &cur_x, &cur_y);
+
+ client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
+ TRUE, FALSE, FALSE);
+ if (config_resize_popup_show == 2) /* == "Always" */
+ popup_coords(moveresize_client, "%d x %d",
+ moveresize_client->frame->area.x,
+ moveresize_client->frame->area.y);
+}
+
+static void do_resize(void)
+{
+ gint x, y, w, h, lw, lh;
+
+ /* see if it is actually going to resize
+ USE cur_x AND cur_y HERE ! Otherwise the try_configure won't know
+ what struts to use !!
+ */
+ x = cur_x;
+ y = cur_y;
+ w = cur_w;
+ h = cur_h;
+ client_try_configure(moveresize_client, &x, &y, &w, &h,
+ &lw, &lh, TRUE);
+ if (!(w == moveresize_client->area.width &&
+ h == moveresize_client->area.height) &&
+ /* if waiting_for_sync == 0, then we aren't waiting.
+ if it is > SYNC_TIMEOUTS, then we have timed out
+ that many times already, so forget about waiting more */
+ (waiting_for_sync == 0 || waiting_for_sync > SYNC_TIMEOUTS))
+ {
+#ifdef SYNC
+ if (config_resize_redraw && obt_display_extension_sync &&
+ /* don't send another sync when one is pending */
+ waiting_for_sync == 0 &&
+ moveresize_client->sync_request &&
+ moveresize_client->sync_counter &&
+ !moveresize_client->not_responding)
+ {
+ XEvent ce;
+ XSyncValue val;
+
+ /* increment the value we're waiting for */
+ ++moveresize_client->sync_counter_value;
+ XSyncIntToValue(&val, moveresize_client->sync_counter_value);