1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 action.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
23 #include "focus_cycle.h"
24 #include "moveresize.h"
37 #include "startupnotify.h"
47 void (*func
)(union ActionData
*);
48 void (*setup
)(ObAction
**, ObUserAction uact
);
51 static ObAction
*action_new(void (*func
)(union ActionData
*data
))
53 ObAction
*a
= g_new0(ObAction
, 1);
60 void action_ref(ObAction
*a
)
65 void action_unref(ObAction
*a
)
67 if (a
== NULL
) return;
69 if (--a
->ref
> 0) return;
71 /* deal with pointers */
72 if (a
->func
== action_execute
|| a
->func
== action_restart
)
73 g_free(a
->data
.execute
.path
);
74 else if (a
->func
== action_debug
)
75 g_free(a
->data
.debug
.string
);
76 else if (a
->func
== action_showmenu
)
77 g_free(a
->data
.showmenu
.name
);
82 ObAction
* action_copy(const ObAction
*src
)
84 ObAction
*a
= action_new(src
->func
);
88 /* deal with pointers */
89 if (a
->func
== action_execute
|| a
->func
== action_restart
)
90 a
->data
.execute
.path
= g_strdup(a
->data
.execute
.path
);
91 else if (a
->func
== action_debug
)
92 a
->data
.debug
.string
= g_strdup(a
->data
.debug
.string
);
93 else if (a
->func
== action_showmenu
)
94 a
->data
.showmenu
.name
= g_strdup(a
->data
.showmenu
.name
);
99 void setup_action_send_to_desktop(ObAction
**a
, ObUserAction uact
)
101 (*a
)->data
.sendto
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
102 (*a
)->data
.sendto
.follow
= TRUE
;
105 void setup_action_send_to_desktop_prev(ObAction
**a
, ObUserAction uact
)
107 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
108 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
109 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_WEST
;
110 (*a
)->data
.sendtodir
.linear
= TRUE
;
111 (*a
)->data
.sendtodir
.wrap
= TRUE
;
112 (*a
)->data
.sendtodir
.follow
= TRUE
;
115 void setup_action_send_to_desktop_next(ObAction
**a
, ObUserAction uact
)
117 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
118 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
119 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_EAST
;
120 (*a
)->data
.sendtodir
.linear
= TRUE
;
121 (*a
)->data
.sendtodir
.wrap
= TRUE
;
122 (*a
)->data
.sendtodir
.follow
= TRUE
;
125 void setup_action_send_to_desktop_left(ObAction
**a
, ObUserAction uact
)
127 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
128 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
129 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_WEST
;
130 (*a
)->data
.sendtodir
.linear
= FALSE
;
131 (*a
)->data
.sendtodir
.wrap
= TRUE
;
132 (*a
)->data
.sendtodir
.follow
= TRUE
;
135 void setup_action_send_to_desktop_right(ObAction
**a
, ObUserAction uact
)
137 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
138 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
139 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_EAST
;
140 (*a
)->data
.sendtodir
.linear
= FALSE
;
141 (*a
)->data
.sendtodir
.wrap
= TRUE
;
142 (*a
)->data
.sendtodir
.follow
= TRUE
;
145 void setup_action_send_to_desktop_up(ObAction
**a
, ObUserAction uact
)
147 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
148 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
149 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_NORTH
;
150 (*a
)->data
.sendtodir
.linear
= FALSE
;
151 (*a
)->data
.sendtodir
.wrap
= TRUE
;
152 (*a
)->data
.sendtodir
.follow
= TRUE
;
155 void setup_action_send_to_desktop_down(ObAction
**a
, ObUserAction uact
)
157 (*a
)->data
.sendtodir
.inter
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
158 (*a
)->data
.sendtodir
.inter
.any
.interactive
= TRUE
;
159 (*a
)->data
.sendtodir
.dir
= OB_DIRECTION_SOUTH
;
160 (*a
)->data
.sendtodir
.linear
= FALSE
;
161 (*a
)->data
.sendtodir
.wrap
= TRUE
;
162 (*a
)->data
.sendtodir
.follow
= TRUE
;
165 void setup_action_desktop(ObAction
**a
, ObUserAction uact
)
168 (*a)->data.desktop.inter.any.interactive = FALSE;
172 void setup_action_desktop_prev(ObAction
**a
, ObUserAction uact
)
174 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
175 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_WEST
;
176 (*a
)->data
.desktopdir
.linear
= TRUE
;
177 (*a
)->data
.desktopdir
.wrap
= TRUE
;
180 void setup_action_desktop_next(ObAction
**a
, ObUserAction uact
)
182 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
183 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_EAST
;
184 (*a
)->data
.desktopdir
.linear
= TRUE
;
185 (*a
)->data
.desktopdir
.wrap
= TRUE
;
188 void setup_action_desktop_left(ObAction
**a
, ObUserAction uact
)
190 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
191 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_WEST
;
192 (*a
)->data
.desktopdir
.linear
= FALSE
;
193 (*a
)->data
.desktopdir
.wrap
= TRUE
;
196 void setup_action_desktop_right(ObAction
**a
, ObUserAction uact
)
198 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
199 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_EAST
;
200 (*a
)->data
.desktopdir
.linear
= FALSE
;
201 (*a
)->data
.desktopdir
.wrap
= TRUE
;
204 void setup_action_desktop_up(ObAction
**a
, ObUserAction uact
)
206 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
207 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_NORTH
;
208 (*a
)->data
.desktopdir
.linear
= FALSE
;
209 (*a
)->data
.desktopdir
.wrap
= TRUE
;
212 void setup_action_desktop_down(ObAction
**a
, ObUserAction uact
)
214 (*a
)->data
.desktopdir
.inter
.any
.interactive
= TRUE
;
215 (*a
)->data
.desktopdir
.dir
= OB_DIRECTION_SOUTH
;
216 (*a
)->data
.desktopdir
.linear
= FALSE
;
217 (*a
)->data
.desktopdir
.wrap
= TRUE
;
220 void setup_action_movefromedge_north(ObAction
**a
, ObUserAction uact
)
222 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
223 (*a
)->data
.diraction
.direction
= OB_DIRECTION_NORTH
;
224 (*a
)->data
.diraction
.hang
= TRUE
;
227 void setup_action_movefromedge_south(ObAction
**a
, ObUserAction uact
)
229 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
230 (*a
)->data
.diraction
.direction
= OB_DIRECTION_SOUTH
;
231 (*a
)->data
.diraction
.hang
= TRUE
;
234 void setup_action_movefromedge_east(ObAction
**a
, ObUserAction uact
)
236 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
237 (*a
)->data
.diraction
.direction
= OB_DIRECTION_EAST
;
238 (*a
)->data
.diraction
.hang
= TRUE
;
241 void setup_action_movefromedge_west(ObAction
**a
, ObUserAction uact
)
243 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
244 (*a
)->data
.diraction
.direction
= OB_DIRECTION_WEST
;
245 (*a
)->data
.diraction
.hang
= TRUE
;
248 void setup_action_movetoedge_north(ObAction
**a
, ObUserAction uact
)
250 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
251 (*a
)->data
.diraction
.direction
= OB_DIRECTION_NORTH
;
252 (*a
)->data
.diraction
.hang
= FALSE
;
255 void setup_action_movetoedge_south(ObAction
**a
, ObUserAction uact
)
257 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
258 (*a
)->data
.diraction
.direction
= OB_DIRECTION_SOUTH
;
259 (*a
)->data
.diraction
.hang
= FALSE
;
262 void setup_action_movetoedge_east(ObAction
**a
, ObUserAction uact
)
264 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
265 (*a
)->data
.diraction
.direction
= OB_DIRECTION_EAST
;
266 (*a
)->data
.diraction
.hang
= FALSE
;
269 void setup_action_movetoedge_west(ObAction
**a
, ObUserAction uact
)
271 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
272 (*a
)->data
.diraction
.direction
= OB_DIRECTION_WEST
;
273 (*a
)->data
.diraction
.hang
= FALSE
;
276 void setup_action_growtoedge_north(ObAction
**a
, ObUserAction uact
)
278 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
279 (*a
)->data
.diraction
.direction
= OB_DIRECTION_NORTH
;
282 void setup_action_growtoedge_south(ObAction
**a
, ObUserAction uact
)
284 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
285 (*a
)->data
.diraction
.direction
= OB_DIRECTION_SOUTH
;
288 void setup_action_growtoedge_east(ObAction
**a
, ObUserAction uact
)
290 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
291 (*a
)->data
.diraction
.direction
= OB_DIRECTION_EAST
;
294 void setup_action_growtoedge_west(ObAction
**a
, ObUserAction uact
)
296 (*a
)->data
.diraction
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
297 (*a
)->data
.diraction
.direction
= OB_DIRECTION_WEST
;
300 void setup_action_top_layer(ObAction
**a
, ObUserAction uact
)
302 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
303 (*a
)->data
.layer
.layer
= 1;
306 void setup_action_normal_layer(ObAction
**a
, ObUserAction uact
)
308 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
309 (*a
)->data
.layer
.layer
= 0;
312 void setup_action_bottom_layer(ObAction
**a
, ObUserAction uact
)
314 (*a
)->data
.layer
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
315 (*a
)->data
.layer
.layer
= -1;
318 void setup_action_resize(ObAction
**a
, ObUserAction uact
)
320 (*a
)->data
.moveresize
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
321 (*a
)->data
.moveresize
.keyboard
=
322 (uact
== OB_USER_ACTION_NONE
||
323 uact
== OB_USER_ACTION_KEYBOARD_KEY
||
324 uact
== OB_USER_ACTION_MENU_SELECTION
);
325 (*a
)->data
.moveresize
.corner
= 0;
328 void setup_action_addremove_desktop_current(ObAction
**a
, ObUserAction uact
)
330 (*a
)->data
.addremovedesktop
.current
= TRUE
;
333 void setup_action_addremove_desktop_last(ObAction
**a
, ObUserAction uact
)
335 (*a
)->data
.addremovedesktop
.current
= FALSE
;
338 void setup_client_action(ObAction
**a
, ObUserAction uact
)
340 (*a
)->data
.any
.client_action
= OB_CLIENT_ACTION_ALWAYS
;
343 ActionString actionstrings
[] =
356 "resizerelativevert",
357 action_resize_relative_vert
,
362 action_resize_relative
,
367 action_send_to_desktop
,
368 setup_action_send_to_desktop
372 action_send_to_desktop_dir
,
373 setup_action_send_to_desktop_next
376 "sendtodesktopprevious",
377 action_send_to_desktop_dir
,
378 setup_action_send_to_desktop_prev
381 "sendtodesktopright",
382 action_send_to_desktop_dir
,
383 setup_action_send_to_desktop_right
387 action_send_to_desktop_dir
,
388 setup_action_send_to_desktop_left
392 action_send_to_desktop_dir
,
393 setup_action_send_to_desktop_up
397 action_send_to_desktop_dir
,
398 setup_action_send_to_desktop_down
408 setup_action_desktop_next
413 setup_action_desktop_prev
418 setup_action_desktop_right
423 setup_action_desktop_left
428 setup_action_desktop_up
433 setup_action_desktop_down
436 "toggledockautohide",
437 action_toggle_dockautohide
,
447 action_send_to_layer
,
448 setup_action_top_layer
453 setup_action_top_layer
457 action_send_to_layer
,
458 setup_action_normal_layer
462 action_send_to_layer
,
463 setup_action_bottom_layer
466 "togglealwaysonbottom",
468 setup_action_bottom_layer
473 setup_action_movefromedge_north
478 setup_action_movefromedge_south
483 setup_action_movefromedge_west
488 setup_action_movefromedge_east
493 setup_action_movetoedge_north
498 setup_action_movetoedge_south
503 setup_action_movetoedge_west
508 setup_action_movetoedge_east
513 setup_action_growtoedge_north
518 setup_action_growtoedge_south
523 setup_action_growtoedge_west
528 setup_action_growtoedge_east
533 setup_action_addremove_desktop_last
537 action_remove_desktop
,
538 setup_action_addremove_desktop_last
543 setup_action_addremove_desktop_current
546 "removedesktopcurrent",
547 action_remove_desktop
,
548 setup_action_addremove_desktop_current
557 /* only key bindings can be interactive. thus saith the xor.
558 because of how the mouse is grabbed, mouse events dont even get
559 read during interactive events, so no dice! >:) */
560 #define INTERACTIVE_LIMIT(a, uact) \
561 if (uact != OB_USER_ACTION_KEYBOARD_KEY) \
562 a->data.any.interactive = FALSE;
564 ObAction
*action_from_string(const gchar
*name
, ObUserAction uact
)
567 gboolean exist
= FALSE
;
570 for (i
= 0; actionstrings
[i
].name
; i
++)
571 if (!g_ascii_strcasecmp(name
, actionstrings
[i
].name
)) {
573 a
= action_new(actionstrings
[i
].func
);
574 if (actionstrings
[i
].setup
)
575 actionstrings
[i
].setup(&a
, uact
);
577 INTERACTIVE_LIMIT(a
, uact
);
581 g_message(_("Invalid action '%s' requested. No such action exists."),
584 g_message(_("Invalid use of action '%s'. Action will be ignored."),
589 ObAction
*action_parse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
593 ObAction
*act
= NULL
;
596 if (parse_attr_string("name", node
, &actname
)) {
597 if ((act
= action_from_string(actname
, uact
))) {
598 } else if (act
->func
== action_resize_relative
) {
599 if ((n
= parse_find_node("left", node
->xmlChildrenNode
)))
600 act
->data
.relative
.deltaxl
= parse_int(doc
, n
);
601 if ((n
= parse_find_node("up", node
->xmlChildrenNode
)))
602 act
->data
.relative
.deltayu
= parse_int(doc
, n
);
603 if ((n
= parse_find_node("right", node
->xmlChildrenNode
)))
604 act
->data
.relative
.deltax
= parse_int(doc
, n
);
605 if ((n
= parse_find_node("down", node
->xmlChildrenNode
)))
606 act
->data
.relative
.deltay
= parse_int(doc
, n
);
607 } else if (act
->func
== action_desktop
) {
608 if ((n
= parse_find_node("desktop", node
->xmlChildrenNode
)))
609 act
->data
.desktop
.desk
= parse_int(doc
, n
);
610 if (act
->data
.desktop
.desk
> 0) act
->data
.desktop
.desk
--;
612 if ((n = parse_find_node("dialog", node->xmlChildrenNode)))
613 act->data.desktop.inter.any.interactive =
616 } else if (act
->func
== action_send_to_desktop
) {
617 if ((n
= parse_find_node("desktop", node
->xmlChildrenNode
)))
618 act
->data
.sendto
.desk
= parse_int(doc
, n
);
619 if (act
->data
.sendto
.desk
> 0) act
->data
.sendto
.desk
--;
620 if ((n
= parse_find_node("follow", node
->xmlChildrenNode
)))
621 act
->data
.sendto
.follow
= parse_bool(doc
, n
);
622 } else if (act
->func
== action_desktop_dir
) {
623 if ((n
= parse_find_node("wrap", node
->xmlChildrenNode
)))
624 act
->data
.desktopdir
.wrap
= parse_bool(doc
, n
);
625 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
626 act
->data
.desktopdir
.inter
.any
.interactive
=
628 } else if (act
->func
== action_send_to_desktop_dir
) {
629 if ((n
= parse_find_node("wrap", node
->xmlChildrenNode
)))
630 act
->data
.sendtodir
.wrap
= parse_bool(doc
, n
);
631 if ((n
= parse_find_node("follow", node
->xmlChildrenNode
)))
632 act
->data
.sendtodir
.follow
= parse_bool(doc
, n
);
633 if ((n
= parse_find_node("dialog", node
->xmlChildrenNode
)))
634 act
->data
.sendtodir
.inter
.any
.interactive
=
636 INTERACTIVE_LIMIT(act
, uact
);
643 void action_run_list(GSList
*acts
, ObClient
*c
, ObFrameContext context
,
644 guint state
, guint button
, gint x
, gint y
, Time time
,
645 gboolean cancel
, gboolean done
)
654 screen_pointer_pos(&x
, &y
);
656 for (it
= acts
; it
; it
= g_slist_next(it
)) {
659 if (!(a
->data
.any
.client_action
== OB_CLIENT_ACTION_ALWAYS
&& !c
)) {
660 a
->data
.any
.c
= a
->data
.any
.client_action
? c
: NULL
;
661 a
->data
.any
.context
= context
;
665 a
->data
.any
.button
= button
;
667 a
->data
.any
.time
= time
;
669 if (a
->data
.any
.interactive
) {
670 a
->data
.inter
.cancel
= cancel
;
671 a
->data
.inter
.final
= done
;
672 if (!(cancel
|| done
))
673 if (!keyboard_interactive_grab(state
, a
->data
.any
.c
, a
))
677 /* XXX UGLY HACK race with motion event starting a move and the
678 button release gettnig processed first. answer: don't queue
679 moveresize starts. UGLY HACK XXX
681 XXX ALSO don't queue showmenu events, because on button press
682 events we need to know if a mouse grab is going to take place,
683 and set the button to 0, so that later motion events don't think
684 that a drag is going on. since showmenu grabs the pointer..
686 if (a
->data
.any
.interactive
|| a
->func
== action_move
||
687 a
->func
== action_resize
|| a
->func
== action_showmenu
)
689 /* interactive actions are not queued */
691 } else if (a
->func
== action_focus
||
692 a
->func
== action_activate
||
693 a
->func
== action_showmenu
)
695 /* XXX MORE UGLY HACK
696 actions from clicks on client windows are NOT queued.
697 this solves the mysterious click-and-drag-doesnt-work
698 problem. it was because the window gets focused and stuff
699 after the button event has already been passed through. i
700 dont really know why it should care but it does and it makes
703 however this very bogus ! !
704 we want to send the button press to the window BEFORE
705 we do the action because the action might move the windows
706 (eg change desktops) and then the button press ends up on
707 the completely wrong window !
708 so, this is just for that bug, and it will only NOT queue it
709 if it is a focusing action that can be used with the mouse
712 also with the menus, there is a race going on. if the
713 desktop wants to pop up a menu, and we do too, we send them
714 the button before we pop up the menu, so they pop up their
715 menu first. but not always. if we pop up our menu before
716 sending them the button press, then the result is
719 XXX further more. focus actions are not queued at all,
720 because if you bind focus->showmenu, the menu will get
721 hidden to do the focusing
725 ob_main_loop_queue_action(ob_main_loop
, a
);
730 void action_run_string(const gchar
*name
, struct _ObClient
*c
, Time time
)
735 a
= action_from_string(name
, OB_USER_ACTION_NONE
);
738 l
= g_slist_append(NULL
, a
);
740 action_run(l
, c
, 0, time
);
743 void action_unshaderaise(union ActionData
*data
)
745 if (data
->client
.any
.c
->shaded
)
746 action_unshade(data
);
751 void action_shadelower(union ActionData
*data
)
753 if (data
->client
.any
.c
->shaded
)
759 void action_resize_relative_horz(union ActionData
*data
)
761 ObClient
*c
= data
->relative
.any
.c
;
762 client_action_start(data
);
764 c
->area
.width
+ data
->relative
.deltax
* c
->size_inc
.width
,
766 client_action_end(data
, FALSE
);
769 void action_resize_relative_vert(union ActionData
*data
)
771 ObClient
*c
= data
->relative
.any
.c
;
773 client_action_start(data
);
774 client_resize(c
, c
->area
.width
, c
->area
.height
+
775 data
->relative
.deltax
* c
->size_inc
.height
);
776 client_action_end(data
, FALSE
);
780 void action_resize_relative(union ActionData
*data
)
782 ObClient
*c
= data
->relative
.any
.c
;
783 gint x
, y
, ow
, xoff
, nw
, oh
, yoff
, nh
, lw
, lh
;
785 client_action_start(data
);
790 xoff
= -data
->relative
.deltaxl
* c
->size_inc
.width
;
791 nw
= ow
+ data
->relative
.deltax
* c
->size_inc
.width
792 + data
->relative
.deltaxl
* c
->size_inc
.width
;
794 yoff
= -data
->relative
.deltayu
* c
->size_inc
.height
;
795 nh
= oh
+ data
->relative
.deltay
* c
->size_inc
.height
796 + data
->relative
.deltayu
* c
->size_inc
.height
;
798 g_print("deltax %d %d x %d ow %d xoff %d nw %d\n",
799 data
->relative
.deltax
,
800 data
->relative
.deltaxl
,
803 client_try_configure(c
, &x
, &y
, &nw
, &nh
, &lw
, &lh
, TRUE
);
804 xoff
= xoff
== 0 ? 0 : (xoff
< 0 ? MAX(xoff
, ow
-nw
) : MIN(xoff
, ow
-nw
));
805 yoff
= yoff
== 0 ? 0 : (yoff
< 0 ? MAX(yoff
, oh
-nh
) : MIN(yoff
, oh
-nh
));
806 client_move_resize(c
, x
+ xoff
, y
+ yoff
, nw
, nh
);
807 client_action_end(data
, FALSE
);
810 void action_send_to_desktop(union ActionData
*data
)
812 ObClient
*c
= data
->sendto
.any
.c
;
814 if (!client_normal(c
)) return;
816 if (data
->sendto
.desk
< screen_num_desktops
||
817 data
->sendto
.desk
== DESKTOP_ALL
) {
818 client_set_desktop(c
, data
->sendto
.desk
, data
->sendto
.follow
, FALSE
);
819 if (data
->sendto
.follow
&& data
->sendto
.desk
!= screen_desktop
)
820 screen_set_desktop(data
->sendto
.desk
, TRUE
);
824 void action_desktop(union ActionData
*data
)
826 /* XXX add the interactive/dialog option back again once the dialog
827 has been made to not use grabs */
828 if (data
->desktop
.desk
< screen_num_desktops
||
829 data
->desktop
.desk
== DESKTOP_ALL
)
831 screen_set_desktop(data
->desktop
.desk
, TRUE
);
832 if (data
->inter
.any
.interactive
)
833 screen_desktop_popup(data
->desktop
.desk
, TRUE
);
837 void action_desktop_dir(union ActionData
*data
)
841 d
= screen_cycle_desktop(data
->desktopdir
.dir
,
842 data
->desktopdir
.wrap
,
843 data
->desktopdir
.linear
,
844 data
->desktopdir
.inter
.any
.interactive
,
845 data
->desktopdir
.inter
.final
,
846 data
->desktopdir
.inter
.cancel
);
847 /* only move the desktop when the action is complete. if we switch
848 desktops during the interactive action, focus will move but with
849 NotifyWhileGrabbed and applications don't like that. */
850 if (!data
->sendtodir
.inter
.any
.interactive
||
851 (data
->sendtodir
.inter
.final
&& !data
->sendtodir
.inter
.cancel
))
853 if (d
!= screen_desktop
)
854 screen_set_desktop(d
, TRUE
);
858 void action_send_to_desktop_dir(union ActionData
*data
)
860 ObClient
*c
= data
->sendtodir
.inter
.any
.c
;
863 if (!client_normal(c
)) return;
865 d
= screen_cycle_desktop(data
->sendtodir
.dir
, data
->sendtodir
.wrap
,
866 data
->sendtodir
.linear
,
867 data
->sendtodir
.inter
.any
.interactive
,
868 data
->sendtodir
.inter
.final
,
869 data
->sendtodir
.inter
.cancel
);
870 /* only move the desktop when the action is complete. if we switch
871 desktops during the interactive action, focus will move but with
872 NotifyWhileGrabbed and applications don't like that. */
873 if (!data
->sendtodir
.inter
.any
.interactive
||
874 (data
->sendtodir
.inter
.final
&& !data
->sendtodir
.inter
.cancel
))
876 client_set_desktop(c
, d
, data
->sendtodir
.follow
, FALSE
);
877 if (data
->sendtodir
.follow
&& d
!= screen_desktop
)
878 screen_set_desktop(d
, TRUE
);
882 void action_desktop_last(union ActionData
*data
)
884 if (screen_last_desktop
< screen_num_desktops
)
885 screen_set_desktop(screen_last_desktop
, TRUE
);
888 void action_directional_focus(union ActionData
*data
)
890 /* if using focus_delay, stop the timer now so that focus doesn't go moving
892 event_halt_focus_delay();
894 focus_directional_cycle(data
->interdiraction
.direction
,
895 data
->interdiraction
.dock_windows
,
896 data
->interdiraction
.desktop_windows
,
897 data
->any
.interactive
,
898 data
->interdiraction
.dialog
,
899 data
->interdiraction
.inter
.final
,
900 data
->interdiraction
.inter
.cancel
);
903 void action_movetoedge(union ActionData
*data
)
906 ObClient
*c
= data
->diraction
.any
.c
;
908 x
= c
->frame
->area
.x
;
909 y
= c
->frame
->area
.y
;
911 switch(data
->diraction
.direction
) {
912 case OB_DIRECTION_NORTH
:
913 y
= client_directional_edge_search(c
, OB_DIRECTION_NORTH
,
914 data
->diraction
.hang
)
915 - (data
->diraction
.hang
? c
->frame
->area
.height
: 0);
917 case OB_DIRECTION_WEST
:
918 x
= client_directional_edge_search(c
, OB_DIRECTION_WEST
,
919 data
->diraction
.hang
)
920 - (data
->diraction
.hang
? c
->frame
->area
.width
: 0);
922 case OB_DIRECTION_SOUTH
:
923 y
= client_directional_edge_search(c
, OB_DIRECTION_SOUTH
,
924 data
->diraction
.hang
)
925 - (data
->diraction
.hang
? 0 : c
->frame
->area
.height
);
927 case OB_DIRECTION_EAST
:
928 x
= client_directional_edge_search(c
, OB_DIRECTION_EAST
,
929 data
->diraction
.hang
)
930 - (data
->diraction
.hang
? 0 : c
->frame
->area
.width
);
933 g_assert_not_reached();
935 frame_frame_gravity(c
->frame
, &x
, &y
, c
->area
.width
, c
->area
.height
);
936 client_action_start(data
);
937 client_move(c
, x
, y
);
938 client_action_end(data
, FALSE
);
941 void action_growtoedge(union ActionData
*data
)
943 gint x
, y
, width
, height
, dest
;
944 ObClient
*c
= data
->diraction
.any
.c
;
947 a
= screen_area(c
->desktop
, SCREEN_AREA_ALL_MONITORS
, &c
->frame
->area
);
948 x
= c
->frame
->area
.x
;
949 y
= c
->frame
->area
.y
;
950 /* get the unshaded frame's dimensions..if it is shaded */
951 width
= c
->area
.width
+ c
->frame
->size
.left
+ c
->frame
->size
.right
;
952 height
= c
->area
.height
+ c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
954 switch(data
->diraction
.direction
) {
955 case OB_DIRECTION_NORTH
:
956 if (c
->shaded
) break; /* don't allow vertical resize if shaded */
958 dest
= client_directional_edge_search(c
, OB_DIRECTION_NORTH
, FALSE
);
962 height
= c
->frame
->area
.y
+ height
- dest
;
966 case OB_DIRECTION_WEST
:
967 dest
= client_directional_edge_search(c
, OB_DIRECTION_WEST
, FALSE
);
971 width
= c
->frame
->area
.x
+ width
- dest
;
975 case OB_DIRECTION_SOUTH
:
976 if (c
->shaded
) break; /* don't allow vertical resize if shaded */
978 dest
= client_directional_edge_search(c
, OB_DIRECTION_SOUTH
, FALSE
);
979 if (a
->y
+ a
->height
== y
+ c
->frame
->area
.height
) {
980 height
= c
->frame
->area
.height
/ 2;
981 y
= a
->y
+ a
->height
- height
;
983 height
= dest
- c
->frame
->area
.y
;
984 y
+= (height
- c
->frame
->area
.height
) % c
->size_inc
.height
;
985 height
-= (height
- c
->frame
->area
.height
) % c
->size_inc
.height
;
987 case OB_DIRECTION_EAST
:
988 dest
= client_directional_edge_search(c
, OB_DIRECTION_EAST
, FALSE
);
989 if (a
->x
+ a
->width
== x
+ c
->frame
->area
.width
) {
990 width
= c
->frame
->area
.width
/ 2;
991 x
= a
->x
+ a
->width
- width
;
993 width
= dest
- c
->frame
->area
.x
;
994 x
+= (width
- c
->frame
->area
.width
) % c
->size_inc
.width
;
995 width
-= (width
- c
->frame
->area
.width
) % c
->size_inc
.width
;
998 g_assert_not_reached();
1000 width
-= c
->frame
->size
.left
+ c
->frame
->size
.right
;
1001 height
-= c
->frame
->size
.top
+ c
->frame
->size
.bottom
;
1002 frame_frame_gravity(c
->frame
, &x
, &y
, width
, height
);
1003 client_action_start(data
);
1004 client_move_resize(c
, x
, y
, width
, height
);
1005 client_action_end(data
, FALSE
);
1009 void action_send_to_layer(union ActionData
*data
)
1011 client_set_layer(data
->layer
.any
.c
, data
->layer
.layer
);
1014 void action_toggle_layer(union ActionData
*data
)
1016 ObClient
*c
= data
->layer
.any
.c
;
1018 client_action_start(data
);
1019 if (data
->layer
.layer
< 0)
1020 client_set_layer(c
, c
->below
? 0 : -1);
1021 else if (data
->layer
.layer
> 0)
1022 client_set_layer(c
, c
->above
? 0 : 1);
1023 client_action_end(data
, config_focus_under_mouse
);
1026 void action_toggle_dockautohide(union ActionData
*data
)
1028 config_dock_hide
= !config_dock_hide
;
1032 void action_add_desktop(union ActionData
*data
)
1034 client_action_start(data
);
1035 screen_set_num_desktops(screen_num_desktops
+1);
1037 /* move all the clients over */
1038 if (data
->addremovedesktop
.current
) {
1041 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1042 ObClient
*c
= it
->data
;
1043 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= screen_desktop
)
1044 client_set_desktop(c
, c
->desktop
+1, FALSE
, TRUE
);
1048 client_action_end(data
, config_focus_under_mouse
);
1051 void action_remove_desktop(union ActionData
*data
)
1053 guint rmdesktop
, movedesktop
;
1054 GList
*it
, *stacking_copy
;
1056 if (screen_num_desktops
< 2) return;
1058 client_action_start(data
);
1060 /* what desktop are we removing and moving to? */
1061 if (data
->addremovedesktop
.current
)
1062 rmdesktop
= screen_desktop
;
1064 rmdesktop
= screen_num_desktops
- 1;
1065 if (rmdesktop
< screen_num_desktops
- 1)
1066 movedesktop
= rmdesktop
+ 1;
1068 movedesktop
= rmdesktop
;
1070 /* make a copy of the list cuz we're changing it */
1071 stacking_copy
= g_list_copy(stacking_list
);
1072 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
1073 if (WINDOW_IS_CLIENT(it
->data
)) {
1074 ObClient
*c
= it
->data
;
1075 guint d
= c
->desktop
;
1076 if (d
!= DESKTOP_ALL
&& d
>= movedesktop
) {
1077 client_set_desktop(c
, c
->desktop
- 1, TRUE
, TRUE
);
1078 ob_debug("moving window %s\n", c
->title
);
1080 /* raise all the windows that are on the current desktop which
1082 if ((screen_desktop
== rmdesktop
- 1 ||
1083 screen_desktop
== rmdesktop
) &&
1084 (d
== DESKTOP_ALL
|| d
== screen_desktop
))
1086 stacking_raise(CLIENT_AS_WINDOW(c
));
1087 ob_debug("raising window %s\n", c
->title
);
1092 /* act like we're changing desktops */
1093 if (screen_desktop
< screen_num_desktops
- 1) {
1094 gint d
= screen_desktop
;
1095 screen_desktop
= screen_last_desktop
;
1096 screen_set_desktop(d
, TRUE
);
1097 ob_debug("fake desktop change\n");
1100 screen_set_num_desktops(screen_num_desktops
-1);
1102 client_action_end(data
, config_focus_under_mouse
);