51
53
static gboolean moving = FALSE; /* TRUE - moving, FALSE - resizing */
55
/* starting geometry for the window being moved/resized, so it can be
53
57
static gint start_x, start_y, start_cx, start_cy, start_cw, start_ch;
58
static gboolean was_max_horz, was_max_vert;
59
static Rect pre_max_area;
54
60
static gint cur_x, cur_y, cur_w, cur_h;
55
61
static guint button;
56
62
static guint32 corner;
57
63
static ObDirection edge_warp_dir = -1;
58
64
static gboolean edge_warp_odd = FALSE;
65
static guint edge_warp_timer = 0;
59
66
static ObDirection key_resize_edge = -1;
67
static guint waiting_for_sync;
61
static gboolean waiting_for_sync;
69
static guint sync_timer = 0;
64
72
static ObPopup *popup = NULL;
179
185
(c->functions & OB_CLIENT_FUNC_RESIZE)))
182
if (cnr == prop_atoms.net_wm_moveresize_size_topleft) {
188
if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) {
183
189
cur = OB_CURSOR_NORTHWEST;
185
} else if (cnr == prop_atoms.net_wm_moveresize_size_top) {
192
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) {
186
193
cur = OB_CURSOR_NORTH;
188
} else if (cnr == prop_atoms.net_wm_moveresize_size_topright) {
196
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) {
189
197
cur = OB_CURSOR_NORTHEAST;
191
} else if (cnr == prop_atoms.net_wm_moveresize_size_right)
200
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT))
192
201
cur = OB_CURSOR_EAST;
193
else if (cnr == prop_atoms.net_wm_moveresize_size_bottomright)
202
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT))
194
203
cur = OB_CURSOR_SOUTHEAST;
195
else if (cnr == prop_atoms.net_wm_moveresize_size_bottom)
204
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM))
196
205
cur = OB_CURSOR_SOUTH;
197
else if (cnr == prop_atoms.net_wm_moveresize_size_bottomleft) {
206
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) {
198
207
cur = OB_CURSOR_SOUTHWEST;
200
} else if (cnr == prop_atoms.net_wm_moveresize_size_left) {
210
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) {
201
211
cur = OB_CURSOR_WEST;
203
} else if (cnr == prop_atoms.net_wm_moveresize_size_keyboard)
214
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD))
204
215
cur = OB_CURSOR_SOUTHEAST;
205
else if (cnr == prop_atoms.net_wm_moveresize_move)
216
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE))
206
217
cur = OB_CURSOR_MOVE;
207
else if (cnr == prop_atoms.net_wm_moveresize_move_keyboard)
218
else if (cnr == OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
208
219
cur = OB_CURSOR_MOVE;
210
221
g_assert_not_reached();
323
337
(cancel ? start_ch : cur_h),
324
338
TRUE, TRUE, FALSE);
340
/* restore the client's maximized state. do this after putting the window
341
back in its original spot to minimize visible flicker */
342
if (cancel && (was_max_horz || was_max_vert)) {
343
const gboolean h = moveresize_client->max_horz;
344
const gboolean v = moveresize_client->max_vert;
346
client_maximize(moveresize_client, TRUE,
347
was_max_horz && was_max_vert ? 0 :
348
(was_max_horz ? 1 : 2));
350
/* replace the premax values with the ones we had saved if
351
the client doesn't have any already set */
352
if (was_max_horz && !h) {
353
moveresize_client->pre_max_area.x = pre_max_area.x;
354
moveresize_client->pre_max_area.width = pre_max_area.width;
356
if (was_max_vert && !v) {
357
moveresize_client->pre_max_area.y = pre_max_area.y;
358
moveresize_client->pre_max_area.height = pre_max_area.height;
326
362
/* dont edge warp after its ended */
327
363
cancel_edge_warp();
353
389
gint x, y, w, h, lw, lh;
355
/* see if it is actually going to resize */
391
/* see if it is actually going to resize
392
USE cur_x AND cur_y HERE ! Otherwise the try_configure won't know
393
what struts to use !!
360
399
client_try_configure(moveresize_client, &x, &y, &w, &h,
362
401
if (!(w == moveresize_client->area.width &&
363
h == moveresize_client->area.height))
402
h == moveresize_client->area.height) &&
403
/* if waiting_for_sync == 0, then we aren't waiting.
404
if it is > SYNC_TIMEOUTS, then we have timed out
405
that many times already, so forget about waiting more */
406
(waiting_for_sync == 0 || waiting_for_sync > SYNC_TIMEOUTS))
367
if (config_resize_redraw && extensions_sync &&
409
if (config_resize_redraw && obt_display_extension_sync &&
410
/* don't send another sync when one is pending */
411
waiting_for_sync == 0 &&
368
412
moveresize_client->sync_request &&
369
413
moveresize_client->sync_counter &&
370
414
!moveresize_client->not_responding)
375
/* are we already waiting for the sync counter to catch up? */
376
if (waiting_for_sync)
379
419
/* increment the value we're waiting for */
380
420
++moveresize_client->sync_counter_value;
381
421
XSyncIntToValue(&val, moveresize_client->sync_counter_value);
383
423
/* tell the client what we're waiting for */
384
424
ce.xclient.type = ClientMessage;
385
ce.xclient.message_type = prop_atoms.wm_protocols;
386
ce.xclient.display = ob_display;
425
ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
426
ce.xclient.display = obt_display;
387
427
ce.xclient.window = moveresize_client->window;
388
428
ce.xclient.format = 32;
389
ce.xclient.data.l[0] = prop_atoms.net_wm_sync_request;
390
ce.xclient.data.l[1] = event_curtime;
429
ce.xclient.data.l[0] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST);
430
ce.xclient.data.l[1] = event_time();
391
431
ce.xclient.data.l[2] = XSyncValueLow32(val);
392
432
ce.xclient.data.l[3] = XSyncValueHigh32(val);
393
433
ce.xclient.data.l[4] = 0l;
394
XSendEvent(ob_display, moveresize_client->window, FALSE,
434
XSendEvent(obt_display, moveresize_client->window, FALSE,
395
435
NoEventMask, &ce);
397
waiting_for_sync = TRUE;
437
waiting_for_sync = 1;
399
ob_main_loop_timeout_remove(ob_main_loop, sync_timeout_func);
400
ob_main_loop_timeout_add(ob_main_loop, G_USEC_PER_SEC * 2,
401
sync_timeout_func, NULL, NULL, NULL);
439
if (sync_timer) g_source_remove(sync_timer);
440
sync_timer = g_timeout_add(2000, sync_timeout_func, NULL);
444
/* force a ConfigureNotify, it is part of the spec for SYNC resizing
445
and MUST follow the sync counter notification */
405
446
client_configure(moveresize_client, cur_x, cur_y, cur_w, cur_h,
409
450
/* this would be better with a fixed width font ... XXX can do it better
588
662
static void cancel_edge_warp(void)
590
ob_main_loop_timeout_remove(ob_main_loop, edge_warp_delay_func);
664
if (edge_warp_timer) g_source_remove(edge_warp_timer);
593
static void move_with_keys(gint keycode, gint state)
668
static void move_with_keys(KeySym sym, guint state)
595
670
gint dx = 0, dy = 0, ox = cur_x, oy = cur_y;
596
671
gint opx, px, opy, py;
599
674
/* shift means jump to edge */
600
if (state & modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT)) {
675
if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT))
604
if (ob_keycode_match(keycode, OB_KEY_RIGHT))
605
681
dir = OB_DIRECTION_EAST;
606
else if (ob_keycode_match(keycode, OB_KEY_LEFT))
682
else if (sym == XK_Left)
607
683
dir = OB_DIRECTION_WEST;
608
else if (ob_keycode_match(keycode, OB_KEY_DOWN))
684
else if (sym == XK_Down)
609
685
dir = OB_DIRECTION_SOUTH;
610
else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */
686
else /* sym == XK_Up */
611
687
dir = OB_DIRECTION_NORTH;
613
689
client_find_move_directional(moveresize_client, dir, &x, &y);
615
691
dy = y - moveresize_client->area.y;
617
693
/* control means fine grained */
618
if (state & modkeys_key_to_mask(OB_MODKEY_KEY_CONTROL))
695
obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_CONTROL))
623
if (ob_keycode_match(keycode, OB_KEY_RIGHT))
625
else if (ob_keycode_match(keycode, OB_KEY_LEFT))
704
else if (sym == XK_Left)
627
else if (ob_keycode_match(keycode, OB_KEY_DOWN))
706
else if (sym == XK_Down)
629
else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */
708
else /* if (sym == XK_Up) */
633
712
screen_pointer_pos(&opx, &opy);
634
XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
713
XWarpPointer(obt_display, None, None, 0, 0, 0, 0, dx, dy);
635
714
/* steal the motion events this causes */
636
XSync(ob_display, FALSE);
715
XSync(obt_display, FALSE);
639
while (XCheckTypedEvent(ob_display, MotionNotify, &ce));
718
while (xqueue_remove_local(&ce, xqueue_match_type,
719
GINT_TO_POINTER(MotionNotify)));
641
721
screen_pointer_pos(&px, &py);
652
732
start_y += (py - opy) - (cur_y - oy);
655
static void resize_with_keys(gint keycode, gint state)
735
static void resize_with_keys(KeySym sym, guint state)
657
737
gint dw = 0, dh = 0, pdx = 0, pdy = 0, opx, opy, px, py;
661
741
/* pick the edge if it needs to move */
662
if (ob_keycode_match(keycode, OB_KEY_RIGHT)) {
742
if (sym == XK_Right) {
663
743
dir = OB_DIRECTION_EAST;
664
744
if (key_resize_edge != OB_DIRECTION_WEST &&
665
745
key_resize_edge != OB_DIRECTION_EAST)
699
776
/* shift means jump to edge */
700
if (state & modkeys_key_to_mask(OB_MODKEY_KEY_SHIFT)) {
777
if (state & obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT))
703
if (ob_keycode_match(keycode, OB_KEY_RIGHT))
704
782
dir = OB_DIRECTION_EAST;
705
else if (ob_keycode_match(keycode, OB_KEY_LEFT))
783
else if (sym == XK_Left)
706
784
dir = OB_DIRECTION_WEST;
707
else if (ob_keycode_match(keycode, OB_KEY_DOWN))
785
else if (sym == XK_Down)
708
786
dir = OB_DIRECTION_SOUTH;
709
else /* if (ob_keycode_match(keycode, OB_KEY_UP)) */
787
else /* if (sym == XK_Up)) */
710
788
dir = OB_DIRECTION_NORTH;
712
790
client_find_resize_directional(moveresize_client, key_resize_edge,
854
if (moveresize_client->max_horz &&
855
(key_resize_edge == OB_DIRECTION_WEST ||
856
key_resize_edge == OB_DIRECTION_EAST))
860
pre_max_area.x = moveresize_client->pre_max_area.x;
861
pre_max_area.width = moveresize_client->pre_max_area.width;
863
moveresize_client->pre_max_area.x = cur_x;
864
moveresize_client->pre_max_area.width = cur_w;
865
client_maximize(moveresize_client, FALSE, 1);
867
else if (moveresize_client->max_vert &&
868
(key_resize_edge == OB_DIRECTION_NORTH ||
869
key_resize_edge == OB_DIRECTION_SOUTH))
873
pre_max_area.y = moveresize_client->pre_max_area.y;
874
pre_max_area.height = moveresize_client->pre_max_area.height;
876
moveresize_client->pre_max_area.y = cur_y;
877
moveresize_client->pre_max_area.height = cur_h;
878
client_maximize(moveresize_client, FALSE, 2);
772
881
calc_resize(TRUE, resist, &dw, &dh, dir);
773
882
if (key_resize_edge == OB_DIRECTION_WEST)
790
899
screen_pointer_pos(&opx, &opy);
791
XWarpPointer(ob_display, None, None, 0, 0, 0, 0, pdx, pdy);
900
XWarpPointer(obt_display, None, None, 0, 0, 0, 0, pdx, pdy);
792
901
/* steal the motion events this causes */
793
XSync(ob_display, FALSE);
902
XSync(obt_display, FALSE);
796
while (XCheckTypedEvent(ob_display, MotionNotify, &ce));
905
while (xqueue_remove_local(&ce, xqueue_match_type,
906
GINT_TO_POINTER(MotionNotify)));
798
908
screen_pointer_pos(&px, &py);
839
if (corner == prop_atoms.net_wm_moveresize_size_topleft) {
949
if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT)) {
840
950
dw = -(e->xmotion.x_root - start_x);
841
951
dh = -(e->xmotion.y_root - start_y);
842
952
dir = OB_DIRECTION_NORTHWEST;
843
} else if (corner == prop_atoms.net_wm_moveresize_size_top) {
953
} else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP)) {
845
955
dh = -(e->xmotion.y_root - start_y);
846
956
dir = OB_DIRECTION_NORTH;
847
} else if (corner == prop_atoms.net_wm_moveresize_size_topright) {
958
OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT)) {
848
959
dw = (e->xmotion.x_root - start_x);
849
960
dh = -(e->xmotion.y_root - start_y);
850
961
dir = OB_DIRECTION_NORTHEAST;
851
} else if (corner == prop_atoms.net_wm_moveresize_size_right) {
962
} else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_RIGHT)) {
852
963
dw = (e->xmotion.x_root - start_x);
854
965
dir = OB_DIRECTION_EAST;
855
966
} else if (corner ==
856
prop_atoms.net_wm_moveresize_size_bottomright) {
967
OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT)) {
857
968
dw = (e->xmotion.x_root - start_x);
858
969
dh = (e->xmotion.y_root - start_y);
859
970
dir = OB_DIRECTION_SOUTHEAST;
860
} else if (corner == prop_atoms.net_wm_moveresize_size_bottom) {
971
} else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOM))
862
974
dh = (e->xmotion.y_root - start_y);
863
975
dir = OB_DIRECTION_SOUTH;
864
976
} else if (corner ==
865
prop_atoms.net_wm_moveresize_size_bottomleft) {
977
OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT)) {
866
978
dw = -(e->xmotion.x_root - start_x);
867
979
dh = (e->xmotion.y_root - start_y);
868
980
dir = OB_DIRECTION_SOUTHWEST;
869
} else if (corner == prop_atoms.net_wm_moveresize_size_left) {
981
} else if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT)) {
870
982
dw = -(e->xmotion.x_root - start_x);
872
984
dir = OB_DIRECTION_WEST;
873
} else if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
986
OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
874
987
dw = (e->xmotion.x_root - start_x);
875
988
dh = (e->xmotion.y_root - start_y);
876
989
dir = OB_DIRECTION_SOUTHEAST;
878
991
g_assert_not_reached();
993
/* override the client's max state if desired */
994
if (ABS(dw) >= config_resist_edge) {
995
if (moveresize_client->max_horz) {
998
pre_max_area.x = moveresize_client->pre_max_area.x;
999
pre_max_area.width = moveresize_client->pre_max_area.width;
1001
moveresize_client->pre_max_area.x = cur_x;
1002
moveresize_client->pre_max_area.width = cur_w;
1003
client_maximize(moveresize_client, FALSE, 1);
1006
else if (was_max_horz && !moveresize_client->max_horz) {
1007
/* remax horz and put the premax back */
1008
client_maximize(moveresize_client, TRUE, 1);
1009
moveresize_client->pre_max_area.x = pre_max_area.x;
1010
moveresize_client->pre_max_area.width = pre_max_area.width;
1013
if (ABS(dh) >= config_resist_edge) {
1014
if (moveresize_client->max_vert) {
1016
was_max_vert = TRUE;
1017
pre_max_area.y = moveresize_client->pre_max_area.y;
1018
pre_max_area.height =
1019
moveresize_client->pre_max_area.height;
1021
moveresize_client->pre_max_area.y = cur_y;
1022
moveresize_client->pre_max_area.height = cur_h;
1023
client_maximize(moveresize_client, FALSE, 2);
1026
else if (was_max_vert && !moveresize_client->max_vert) {
1027
/* remax vert and put the premax back */
1028
client_maximize(moveresize_client, TRUE, 2);
1029
moveresize_client->pre_max_area.y = pre_max_area.y;
1030
moveresize_client->pre_max_area.height = pre_max_area.height;
880
1033
dw -= cur_w - start_cw;
881
1034
dh -= cur_h - start_ch;
887
if (corner == prop_atoms.net_wm_moveresize_size_topleft ||
888
corner == prop_atoms.net_wm_moveresize_size_left ||
889
corner == prop_atoms.net_wm_moveresize_size_bottomleft)
1040
if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
1041
corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_LEFT) ||
1042
corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT))
893
if (corner == prop_atoms.net_wm_moveresize_size_topleft ||
894
corner == prop_atoms.net_wm_moveresize_size_top ||
895
corner == prop_atoms.net_wm_moveresize_size_topright)
1046
if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPLEFT) ||
1047
corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOP) ||
1048
corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_TOPRIGHT))
903
1056
} else if (e->type == KeyPress) {
904
if (ob_keycode_match(e->xkey.keycode, OB_KEY_ESCAPE)) {
1057
KeySym sym = obt_keyboard_keypress_to_keysym(e);
1059
if (sym == XK_Escape) {
905
1060
moveresize_end(TRUE);
907
} else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RETURN)) {
1062
} else if (sym == XK_Return || sym == XK_KP_Enter) {
908
1063
moveresize_end(FALSE);
910
} else if (ob_keycode_match(e->xkey.keycode, OB_KEY_RIGHT) ||
911
ob_keycode_match(e->xkey.keycode, OB_KEY_LEFT) ||
912
ob_keycode_match(e->xkey.keycode, OB_KEY_DOWN) ||
913
ob_keycode_match(e->xkey.keycode, OB_KEY_UP))
1065
} else if (sym == XK_Right || sym == XK_Left ||
1066
sym == XK_Up || sym == XK_Down)
915
if (corner == prop_atoms.net_wm_moveresize_size_keyboard) {
916
resize_with_keys(e->xkey.keycode, e->xkey.state);
1068
if (corner == OBT_PROP_ATOM(NET_WM_MOVERESIZE_SIZE_KEYBOARD)) {
1069
resize_with_keys(sym, e->xkey.state);
918
} else if (corner == prop_atoms.net_wm_moveresize_move_keyboard) {
919
move_with_keys(e->xkey.keycode, e->xkey.state);
1071
} else if (corner ==
1072
OBT_PROP_ATOM(NET_WM_MOVERESIZE_MOVE_KEYBOARD))
1074
move_with_keys(sym, e->xkey.state);
925
else if (e->type == extensions_sync_event_basep + XSyncAlarmNotify)
1080
else if (e->type == obt_display_extension_sync_basep + XSyncAlarmNotify)
927
waiting_for_sync = FALSE; /* we got our sync... */
1082
waiting_for_sync = 0; /* we got our sync... */
928
1083
do_resize(); /* ...so try resize if there is more change pending */
1088
if (used && moveresize_client == focus_client)
1089
event_update_user_time();