2 * client.c - client management
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <xcb/xtest.h>
23 #include <xcb/xcb_atom.h>
24 #include <xcb/xcb_image.h>
35 #include "common/atoms.h"
37 extern awesome_t globalconf
;
39 DO_LUA_NEW(extern, client_t
, client
, "client", client_ref
)
40 DO_LUA_EQ(client_t
, client
, "client")
41 DO_LUA_GC(client_t
, client
, "client", client_unref
)
43 /** Load windows properties, restoring client's tag
44 * and floating state before awesome was restarted if any.
45 * \param c A client pointer.
46 * \param screen A virtual screen.
47 * \return True if client had property, false otherwise.
50 client_loadprops(client_t
* c
, screen_t
*screen
)
53 tag_array_t
*tags
= &screen
->tags
;
55 xcb_get_property_cookie_t fullscreen_q
;
56 xcb_get_property_reply_t
*reply
;
59 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _AWESOME_TAGS
,
63 /* Send the GetProperty requests which will be processed later */
64 fullscreen_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
65 _AWESOME_FULLSCREEN
, CARDINAL
, 0, 1);
67 /* ignore property if the tag count isn't matching */
69 for(int i
= 0; i
< tags
->len
; i
++)
72 tag_client(c
, tags
->tab
[i
]);
74 untag_client(c
, tags
->tab
[i
]);
79 /* check for fullscreen */
80 reply
= xcb_get_property_reply(globalconf
.connection
, fullscreen_q
, NULL
);
82 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
83 client_setfullscreen(c
, *(bool *) data
);
89 /** Check if client supports protocol a protocole in WM_PROTOCOL.
90 * \param win The window.
91 * \return True if client has the atom in protocol, false otherwise.
94 window_hasproto(xcb_window_t win
, xcb_atom_t atom
)
97 xcb_get_wm_protocols_reply_t protocols
;
100 if(xcb_get_wm_protocols_reply(globalconf
.connection
,
101 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
105 for(i
= 0; !ret
&& i
< protocols
.atoms_len
; i
++)
106 if(protocols
.atoms
[i
] == atom
)
108 xcb_get_wm_protocols_reply_wipe(&protocols
);
113 /** Returns true if a client is tagged
114 * with one of the tags of the specified screen.
115 * \param c The client to check.
116 * \param screen Virtual screen number.
117 * \return true if the client is visible, false otherwise.
120 client_maybevisible(client_t
*c
, int screen
)
122 if(c
->screen
== screen
)
124 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
127 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
129 for(int i
= 0; i
< tags
->len
; i
++)
130 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
136 /** Return the content of a client as an image.
137 * That's just take a screenshot.
138 * \param c The client.
142 client_getcontent(client_t
*c
)
144 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
147 c
->geometries
.internal
.width
,
148 c
->geometries
.internal
.height
,
149 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
151 if(!ximage
|| ximage
->bpp
< 24)
154 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
156 for(int y
= 0; y
< ximage
->height
; y
++)
157 for(int x
= 0; x
< ximage
->width
; x
++)
159 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
160 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
163 image_t
*image
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
165 xcb_image_destroy(ximage
);
170 /** Get a client by its window.
171 * \param w The client window to find.
172 * \return A client pointer if found, NULL otherwise.
175 client_getbywin(xcb_window_t w
)
178 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
182 /** Unfocus a client.
183 * \param c The client.
186 client_unfocus(client_t
*c
)
188 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
189 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
191 /* Set focus on root window, so no events leak to the current window. */
193 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
194 root_win
, XCB_CURRENT_TIME
);
197 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
199 luaA_client_userdata_new(globalconf
.L
, c
);
200 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
203 ewmh_update_net_active_window(c
->phys_screen
);
206 /** Ban client and move it out of the viewport.
207 * \param c The client.
210 client_ban(client_t
*c
)
214 /* Move all clients out of the physical viewport into negative coordinate space. */
215 /* They will all be put on top of each other. */
216 uint32_t request
[2] = { - (c
->geometries
.internal
.width
+ 2 * c
->border
),
217 - (c
->geometries
.internal
.height
+ 2 * c
->border
) };
219 xcb_configure_window(globalconf
.connection
, c
->win
,
220 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
223 /* Do it manually because client geometry remains unchanged. */
226 simple_window_t
*sw
= &c
->titlebar
->sw
;
230 request
[0] = - (sw
->geometry
.width
);
231 request
[1] = - (sw
->geometry
.height
);
232 /* Move the titlebar to the same place as the window. */
233 xcb_configure_window(globalconf
.connection
, sw
->window
,
234 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
241 /* All the wiboxes (may) need to be repositioned. */
242 if(client_hasstrut(c
))
243 wibox_update_positions();
246 /* Wait until the last moment to take away the focus from the window. */
247 if (globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
251 /** Give focus to client, or to first client if client is NULL.
252 * \param c The client or NULL.
253 * \return True if a window (even root) has received focus, false otherwise.
256 client_focus(client_t
*c
)
258 if(!client_maybevisible(c
, c
->screen
))
261 /* unfocus current selected client */
262 if(globalconf
.screen_focus
->client_focus
263 && c
!= globalconf
.screen_focus
->client_focus
)
264 client_unfocus(globalconf
.screen_focus
->client_focus
);
268 client_setminimized(c
, false);
270 /* unban the client before focusing or it will fail */
273 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
274 globalconf
.screen_focus
->client_focus
= c
;
277 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
278 c
->win
, XCB_CURRENT_TIME
);
280 /* Some layouts use focused client differently, so call them back.
281 * And anyway, we have maybe unhidden */
282 client_need_arrange(c
);
285 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
287 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
288 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
291 ewmh_update_net_active_window(c
->phys_screen
);
294 /** Stack a window below.
295 * \param c The client.
296 * \param previous The previous window on the stack.
297 * \param return The next-previous!
300 client_stack_above(client_t
*c
, xcb_window_t previous
)
302 uint32_t config_win_vals
[2];
304 config_win_vals
[0] = previous
;
305 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
307 xcb_configure_window(globalconf
.connection
, c
->win
,
308 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
311 config_win_vals
[0] = c
->win
;
315 xcb_configure_window(globalconf
.connection
,
316 c
->titlebar
->sw
.window
,
317 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
319 previous
= c
->titlebar
->sw
.window
;
324 /* stack transient window on top of their parents */
325 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
326 node
; node
= node
->prev
)
327 if(node
->client
->transient_for
== c
)
329 client_stack_above(node
->client
,
331 previous
= node
->client
->win
;
337 /** Stacking layout layers */
340 /** This one is a special layer */
351 /** Get the real layer of a client according to its attribute (fullscreen, …)
352 * \param c The client.
353 * \return The real layer.
356 client_layer_translator(client_t
*c
)
358 /* first deal with user set attributes */
361 else if(c
->isfullscreen
)
362 return LAYER_FULLSCREEN
;
368 /* check for transient attr */
372 /* then deal with windows type */
375 case WINDOW_TYPE_DOCK
:
377 case WINDOW_TYPE_DESKTOP
:
378 return LAYER_DESKTOP
;
379 case WINDOW_TYPE_DIALOG
:
380 case WINDOW_TYPE_MENU
:
381 case WINDOW_TYPE_TOOLBAR
:
382 case WINDOW_TYPE_UTILITY
:
392 * \todo It might be worth stopping to restack everyone and only stack `c'
393 * relatively to the first matching in the list.
398 uint32_t config_win_vals
[2];
399 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
403 config_win_vals
[0] = XCB_NONE
;
404 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
406 /* stack desktop windows */
407 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
408 for(node
= last
; node
; node
= node
->prev
)
409 if(client_layer_translator(node
->client
) == layer
)
410 config_win_vals
[0] = client_stack_above(node
->client
,
413 /* first stack not ontop wibox window */
414 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
415 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
417 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
420 xcb_configure_window(globalconf
.connection
,
422 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
424 config_win_vals
[0] = sb
->sw
.window
;
428 /* stack bottom layers */
429 for(layer
= LAYER_BELOW
; layer
< LAYER_FULLSCREEN
; layer
++)
430 for(node
= last
; node
; node
= node
->prev
)
431 if(client_layer_translator(node
->client
) == layer
)
432 config_win_vals
[0] = client_stack_above(node
->client
,
435 /* then stack ontop wibox window */
436 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
437 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
439 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
442 xcb_configure_window(globalconf
.connection
,
444 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
446 config_win_vals
[0] = sb
->sw
.window
;
450 /* finally stack ontop and fullscreen windows */
451 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
452 for(node
= last
; node
; node
= node
->prev
)
453 if(client_layer_translator(node
->client
) == layer
)
454 config_win_vals
[0] = client_stack_above(node
->client
,
458 /** Copy tags from one client to another client on the same screen.
459 * Be careful: this does not untag!
460 * \param src_c The source client.
461 * \param dst_c The destination client.
464 client_duplicate_tags(client_t
*src_c
, client_t
*dst_c
)
467 tag_array_t
*tags
= &globalconf
.screens
[src_c
->screen
].tags
;
469 /* Avoid doing dangerous things. */
470 if (src_c
->screen
!= dst_c
->screen
)
473 for(i
= 0; i
< tags
->len
; i
++)
474 if(is_client_tagged(src_c
, tags
->tab
[i
]))
475 tag_client(dst_c
, tags
->tab
[i
]);
478 /** Manage a new client.
479 * \param w The window.
480 * \param wgeom Window geometry.
481 * \param phys_screen Physical screen number.
482 * \param startup True if we are managing at startup time.
485 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
487 xcb_get_property_cookie_t ewmh_icon_cookie
;
488 client_t
*c
, *tc
= NULL
, *group
= NULL
;
491 const uint32_t select_input_val
[] =
493 XCB_EVENT_MASK_STRUCTURE_NOTIFY
494 | XCB_EVENT_MASK_PROPERTY_CHANGE
495 | XCB_EVENT_MASK_ENTER_WINDOW
496 | XCB_EVENT_MASK_LEAVE_WINDOW
500 if(systray_iskdedockapp(w
))
502 systray_request_handle(w
, phys_screen
, NULL
);
506 /* Send request to get NET_WM_ICON property as soon as possible... */
507 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
508 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
509 c
= p_new(client_t
, 1);
511 screen
= c
->screen
= screen_getbycoord(phys_screen
, wgeom
->x
, wgeom
->y
);
513 c
->phys_screen
= phys_screen
;
517 c
->geometry
.x
= wgeom
->x
;
518 c
->geometry
.y
= wgeom
->y
;
519 c
->geometry
.width
= wgeom
->width
+ 2 * wgeom
->border_width
;
520 c
->geometry
.height
= wgeom
->height
+ 2 * wgeom
->border_width
;
521 /* Also set internal geometry (client_ban() needs it). */
522 c
->geometries
.internal
.x
= wgeom
->x
;
523 c
->geometries
.internal
.y
= wgeom
->y
;
524 c
->geometries
.internal
.width
= wgeom
->width
;
525 c
->geometries
.internal
.height
= wgeom
->height
;
526 client_setborder(c
, wgeom
->border_width
);
527 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
528 c
->icon
= image_ref(&icon
);
530 /* we honor size hints by default */
531 c
->size_hints_honor
= true;
534 property_update_wm_normal_hints(c
, NULL
);
535 property_update_wm_hints(c
, NULL
);
536 property_update_wm_transient_for(c
, NULL
);
537 property_update_wm_client_leader(c
, NULL
);
539 /* Recursively find the parent. */
540 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
544 /* Try to load props, if it fails check for group windows.
545 * transient_for windows are excluded, because they inherit the parent tags. */
546 if(!client_loadprops(c
, &globalconf
.screens
[screen
])
548 && !c
->transient_for
)
549 /* Try to find a group of windows for better initial placement. */
550 for(group
= globalconf
.clients
; group
; group
= group
->next
)
551 if(group
->group_win
== c
->group_win
)
554 /* Move to the right screen.
555 * Assumption: Window groups do not span multiple logical screens. */
556 if(group
&& group
->phys_screen
== c
->phys_screen
)
557 screen_client_moveto(c
, group
->screen
, false, true);
559 /* Then check clients hints */
560 ewmh_client_check_hints(c
);
562 /* move client to screen, but do not tag it for now */
563 screen_client_moveto(c
, screen
, false, true);
565 /* Duplicate the tags of either the parent or a group window.
566 * Otherwise check for existing tags, if that fails tag it with the current tag.
567 * This could be done lua side, but it's sane behaviour. */
571 client_duplicate_tags(tc
, c
);
573 client_duplicate_tags(group
, c
);
577 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
578 for(i
= 0; i
< tags
->len
; i
++)
579 if(is_client_tagged(c
, tags
->tab
[i
]))
582 /* if no tag, set current selected */
584 for(i
= 0; i
< tags
->len
; i
++)
585 if(tags
->tab
[i
]->selected
)
586 tag_client(c
, tags
->tab
[i
]);
590 /* Push client in client list */
591 client_list_push(&globalconf
.clients
, client_ref(&c
));
593 /* Push client in stack */
596 /* update window title */
597 property_update_wm_name(c
);
598 property_update_wm_icon_name(c
);
601 ewmh_client_strut_update(c
, NULL
);
603 ewmh_update_net_client_list(c
->phys_screen
);
605 /* Always stay in NORMAL_STATE. Even though iconified seems more
606 * appropriate sometimes. The only possible loss is that clients not using
607 * visibility events may continue to proces data (when banned).
608 * Without any exposes or other events the cost should be fairly limited though.
610 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
611 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
613 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
614 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
616 * "Once a client's window has left the Withdrawn state, the window will be mapped
617 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
619 * At this stage it's just safer to keep it in normal state and avoid confusion.
621 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
623 /* Move window outside the viewport before mapping it. */
625 xcb_map_window(globalconf
.connection
, c
->win
);
627 /* Call hook to notify list change */
628 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
629 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
632 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
634 luaA_client_userdata_new(globalconf
.L
, c
);
635 lua_pushboolean(globalconf
.L
, startup
);
636 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
640 /** Compute client geometry with respect to its geometry hints.
641 * \param c The client.
642 * \param geometry The geometry that the client might receive.
643 * \return The geometry the client must take respecting its hints.
646 client_geometry_hints(client_t
*c
, area_t geometry
)
648 int32_t basew
, baseh
, minw
, minh
;
650 /* base size is substituted with min size if not specified */
651 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
653 basew
= c
->size_hints
.base_width
;
654 baseh
= c
->size_hints
.base_height
;
656 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
658 basew
= c
->size_hints
.min_width
;
659 baseh
= c
->size_hints
.min_height
;
664 /* min size is substituted with base size if not specified */
665 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
667 minw
= c
->size_hints
.min_width
;
668 minh
= c
->size_hints
.min_height
;
670 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
672 minw
= c
->size_hints
.base_width
;
673 minh
= c
->size_hints
.base_height
;
678 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
679 && c
->size_hints
.min_aspect_num
> 0
680 && c
->size_hints
.min_aspect_den
> 0
681 && geometry
.height
- baseh
> 0
682 && geometry
.width
- basew
> 0)
684 double dx
= (double) (geometry
.width
- basew
);
685 double dy
= (double) (geometry
.height
- baseh
);
686 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
687 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
688 double ratio
= dx
/ dy
;
689 if(max
> 0 && min
> 0 && ratio
> 0)
693 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
695 geometry
.width
= (int) dx
+ basew
;
696 geometry
.height
= (int) dy
+ baseh
;
700 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
702 geometry
.width
= (int) dx
+ basew
;
703 geometry
.height
= (int) dy
+ baseh
;
709 geometry
.width
= MAX(geometry
.width
, minw
);
711 geometry
.height
= MAX(geometry
.height
, minh
);
713 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
715 if(c
->size_hints
.max_width
)
716 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
717 if(c
->size_hints
.max_height
)
718 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
721 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
722 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
724 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
725 unsigned_subtract(t1
, basew
);
726 unsigned_subtract(t2
, baseh
);
727 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
728 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
734 /** Resize client window.
735 * The sizse given as parameters are with titlebar and borders!
736 * \param c Client to resize.
737 * \param geometry New window geometry.
738 * \param hints Use size hints.
741 client_resize(client_t
*c
, area_t geometry
, bool hints
)
744 area_t geometry_internal
;
747 /* offscreen appearance fixes */
748 area
= display_area_get(c
->phys_screen
, NULL
,
749 &globalconf
.screens
[c
->screen
].padding
);
751 if(geometry
.x
> area
.width
)
752 geometry
.x
= area
.width
- geometry
.width
;
753 if(geometry
.y
> area
.height
)
754 geometry
.y
= area
.height
- geometry
.height
;
755 if(geometry
.x
+ geometry
.width
< 0)
757 if(geometry
.y
+ geometry
.height
< 0)
760 /* Real client geometry, please keep it contained to C code at the very least. */
761 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
764 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
766 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
769 /* Also let client hints propegate to the "official" geometry. */
770 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
772 if(c
->geometries
.internal
.x
!= geometry_internal
.x
773 || c
->geometries
.internal
.y
!= geometry_internal
.y
774 || c
->geometries
.internal
.width
!= geometry_internal
.width
775 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
777 new_screen
= screen_getbycoord(c
->screen
, geometry_internal
.x
, geometry_internal
.y
);
779 /* Values to configure a window is an array where values are
780 * stored according to 'value_mask' */
783 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
784 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
785 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
786 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
788 /* Also store geometry including border and titlebar. */
789 c
->geometry
= geometry
;
791 titlebar_update_geometry(c
);
793 /* The idea is to give a client a resize even when banned. */
794 /* We just have to move the (x,y) to keep it out of the viewport. */
795 /* This at least doesn't break expectations about events. */
798 geometry
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
799 geometry
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
802 xcb_configure_window(globalconf
.connection
, c
->win
,
803 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
804 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
806 window_configure(c
->win
, geometry_internal
, c
->border
);
808 screen_client_moveto(c
, new_screen
, true, false);
811 hooks_property(c
, "geometry");
815 /** Set a client minimized, or not.
816 * \param c The client.
817 * \param s Set or not the client minimized.
820 client_setminimized(client_t
*c
, bool s
)
822 if(c
->isminimized
!= s
)
824 client_need_arrange(c
);
826 client_need_arrange(c
);
827 ewmh_client_update_hints(c
);
829 hooks_property(c
, "minimized");
833 /** Set a client sticky, or not.
834 * \param c The client.
835 * \param s Set or not the client sticky.
838 client_setsticky(client_t
*c
, bool s
)
842 client_need_arrange(c
);
844 client_need_arrange(c
);
845 ewmh_client_update_hints(c
);
846 hooks_property(c
, "sticky");
850 /** Set a client fullscreen, or not.
851 * \param c The client.
852 * \param s Set or not the client fullscreen.
855 client_setfullscreen(client_t
*c
, bool s
)
857 if(c
->isfullscreen
!= s
)
861 /* become fullscreen! */
862 if((c
->isfullscreen
= s
))
864 /* remove any max state */
865 client_setmaxhoriz(c
, false);
866 client_setmaxvert(c
, false);
868 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
869 c
->geometries
.fullscreen
= c
->geometry
;
870 c
->border_fs
= c
->border
;
871 client_setborder(c
, 0);
875 geometry
= c
->geometries
.fullscreen
;
876 client_setborder(c
, c
->border_fs
);
878 client_resize(c
, geometry
, false);
879 client_need_arrange(c
);
881 xcb_change_property(globalconf
.connection
,
882 XCB_PROP_MODE_REPLACE
,
883 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
885 ewmh_client_update_hints(c
);
886 hooks_property(c
, "fullscreen");
890 /** Set a client horizontally maximized.
891 * \param c The client.
892 * \param s The maximized status.
895 client_setmaxhoriz(client_t
*c
, bool s
)
897 if(c
->ismaxhoriz
!= s
)
901 if((c
->ismaxhoriz
= s
))
903 /* remove fullscreen mode */
904 client_setfullscreen(c
, false);
906 geometry
= screen_area_get(c
->screen
,
907 &globalconf
.screens
[c
->screen
].wiboxes
,
908 &globalconf
.screens
[c
->screen
].padding
,
910 geometry
.y
= c
->geometry
.y
;
911 geometry
.height
= c
->geometry
.height
;
912 c
->geometries
.max
.x
= c
->geometry
.x
;
913 c
->geometries
.max
.width
= c
->geometry
.width
;
917 geometry
= c
->geometry
;
918 geometry
.x
= c
->geometries
.max
.x
;
919 geometry
.width
= c
->geometries
.max
.width
;
922 client_resize(c
, geometry
, c
->size_hints_honor
);
923 client_need_arrange(c
);
925 ewmh_client_update_hints(c
);
926 hooks_property(c
, "maximized_horizontal");
930 /** Set a client vertically maximized.
931 * \param c The client.
932 * \param s The maximized status.
935 client_setmaxvert(client_t
*c
, bool s
)
937 if(c
->ismaxvert
!= s
)
941 if((c
->ismaxvert
= s
))
943 /* remove fullscreen mode */
944 client_setfullscreen(c
, false);
946 geometry
= screen_area_get(c
->screen
,
947 &globalconf
.screens
[c
->screen
].wiboxes
,
948 &globalconf
.screens
[c
->screen
].padding
,
950 geometry
.x
= c
->geometry
.x
;
951 geometry
.width
= c
->geometry
.width
;
952 c
->geometries
.max
.y
= c
->geometry
.y
;
953 c
->geometries
.max
.height
= c
->geometry
.height
;
957 geometry
= c
->geometry
;
958 geometry
.y
= c
->geometries
.max
.y
;
959 geometry
.height
= c
->geometries
.max
.height
;
962 client_resize(c
, geometry
, c
->size_hints_honor
);
963 client_need_arrange(c
);
965 ewmh_client_update_hints(c
);
966 hooks_property(c
, "maximized_vertical");
970 /** Set a client above, or not.
971 * \param c The client.
972 * \param s Set or not the client above.
975 client_setabove(client_t
*c
, bool s
)
981 ewmh_client_update_hints(c
);
983 hooks_property(c
, "above");
987 /** Set a client below, or not.
988 * \param c The client.
989 * \param s Set or not the client below.
992 client_setbelow(client_t
*c
, bool s
)
998 ewmh_client_update_hints(c
);
1000 hooks_property(c
, "below");
1004 /** Set a client modal, or not.
1005 * \param c The client.
1006 * \param s Set or not the client moda.
1009 client_setmodal(client_t
*c
, bool s
)
1015 ewmh_client_update_hints(c
);
1017 hooks_property(c
, "modal");
1021 /** Set a client ontop, or not.
1022 * \param c The client.
1023 * \param s Set or not the client moda.
1026 client_setontop(client_t
*c
, bool s
)
1033 hooks_property(c
, "ontop");
1037 /** Save client properties as an X property.
1038 * \param c The client.
1041 client_saveprops_tags(client_t
*c
)
1043 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1044 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
1047 for(i
= 0; i
< tags
->len
; i
++)
1048 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
1050 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
1053 /** Unban a client and move it back into the viewport.
1054 * \param c The client.
1057 client_unban(client_t
*c
)
1061 /* Move the client back where it belongs. */
1062 uint32_t request
[2] = { c
->geometries
.internal
.x
, c
->geometries
.internal
.y
};
1064 xcb_configure_window(globalconf
.connection
, c
->win
,
1065 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
1067 window_configure(c
->win
, c
->geometries
.internal
, c
->border
);
1069 /* Do this manually because the system doesn't know we moved the toolbar.
1070 * Note that !isvisible titlebars are unmapped and for fullscreen it'll
1071 * end up offscreen anyway. */
1074 simple_window_t
*sw
= &c
->titlebar
->sw
;
1075 /* All resizing is done, so only move now. */
1076 request
[0] = sw
->geometry
.x
;
1077 request
[1] = sw
->geometry
.y
;
1079 xcb_configure_window(globalconf
.connection
, sw
->window
,
1080 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
1084 c
->isbanned
= false;
1086 /* All the wiboxes (may) need to be repositioned. */
1087 if(client_hasstrut(c
))
1088 wibox_update_positions();
1092 /** Unmanage a client.
1093 * \param c The client.
1096 client_unmanage(client_t
*c
)
1098 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1100 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
1103 /* remove client everywhere */
1104 client_list_detach(&globalconf
.clients
, c
);
1105 stack_client_delete(c
);
1106 for(int i
= 0; i
< tags
->len
; i
++)
1107 untag_client(c
, tags
->tab
[i
]);
1110 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1112 luaA_client_userdata_new(globalconf
.L
, c
);
1113 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1116 /* Call hook to notify list change */
1117 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1118 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1120 /* The server grab construct avoids race conditions. */
1121 xcb_grab_server(globalconf
.connection
);
1123 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1124 XCB_BUTTON_MASK_ANY
);
1125 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1127 xcb_flush(globalconf
.connection
);
1128 xcb_ungrab_server(globalconf
.connection
);
1130 titlebar_client_detach(c
);
1132 ewmh_update_net_client_list(c
->phys_screen
);
1134 /* delete properties */
1135 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
1136 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
1138 /* All the wiboxes (may) need to be repositioned. */
1139 if(client_hasstrut(c
))
1140 wibox_update_positions();
1142 /* set client as invalid */
1148 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1150 * \param c The client to kill.
1153 client_kill(client_t
*c
)
1155 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1157 xcb_client_message_event_t ev
;
1159 /* Initialize all of event's fields first */
1162 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1165 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1166 ev
.type
= WM_PROTOCOLS
;
1167 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1169 xcb_send_event(globalconf
.connection
, false, c
->win
,
1170 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1173 xcb_kill_client(globalconf
.connection
, c
->win
);
1176 /** Get all clients into a table.
1177 * \param L The Lua VM state.
1178 * \return The number of elements pushed on stack.
1180 * \lparam An optional screen nunmber.
1181 * \lreturn A table with all clients.
1184 luaA_client_get(lua_State
*L
)
1189 screen
= luaL_optnumber(L
, 1, 0) - 1;
1193 if(screen
== SCREEN_UNDEF
)
1194 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1196 luaA_client_userdata_new(globalconf
.L
, c
);
1197 lua_rawseti(L
, -2, i
++);
1201 luaA_checkscreen(screen
);
1202 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1203 if(c
->screen
== screen
)
1205 luaA_client_userdata_new(globalconf
.L
, c
);
1206 lua_rawseti(L
, -2, i
++);
1213 /** Check if a client is visible on its screen.
1214 * \param L The Lua VM state.
1215 * \return The number of elements pushed on stack.
1218 * \lreturn A boolean value, true if the client is visible, false otherwise.
1221 luaA_client_isvisible(lua_State
*L
)
1223 client_t
**c
= luaA_checkudata(L
, 1, "client");
1224 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
1228 /** Set client border width.
1229 * \param c The client.
1230 * \param width The border width.
1233 client_setborder(client_t
*c
, int width
)
1237 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1238 || c
->type
== WINDOW_TYPE_SPLASH
1239 || c
->type
== WINDOW_TYPE_DESKTOP
1240 || c
->isfullscreen
))
1243 if(width
== c
->border
|| width
< 0)
1247 xcb_configure_window(globalconf
.connection
, c
->win
,
1248 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1250 client_need_arrange(c
);
1252 hooks_property(c
, "border_width");
1256 * \param L The Lua VM state.
1262 luaA_client_kill(lua_State
*L
)
1264 client_t
**c
= luaA_checkudata(L
, 1, "client");
1269 /** Swap a client with another one.
1270 * \param L The Lua VM state.
1273 * \lparam A client to swap with.
1276 luaA_client_swap(lua_State
*L
)
1278 client_t
**c
= luaA_checkudata(L
, 1, "client");
1279 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1283 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1284 client_need_arrange(*c
);
1285 client_need_arrange(*swap
);
1287 /* Call hook to notify list change */
1288 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1289 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1295 /** Access or set the client tags.
1296 * \param L The Lua VM state.
1297 * \return The number of elements pushed on stack.
1298 * \lparam A table with tags to set, or none to get the current tags table.
1299 * \return The clients tag.
1302 luaA_client_tags(lua_State
*L
)
1306 client_t
**c
= luaA_checkudata(L
, 1, "client");
1309 if(lua_gettop(L
) == 2)
1311 luaA_checktable(L
, 2);
1312 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1313 for(int i
= 0; i
< tags
->len
; i
++)
1314 untag_client(*c
, tags
->tab
[i
]);
1316 while(lua_next(L
, 2))
1318 tag
= luaA_checkudata(L
, -1, "tag");
1319 tag_client(*c
, *tag
);
1325 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1327 for(int i
= 0; i
< tags
->len
; i
++)
1328 if(is_client_tagged(*c
, tags
->tab
[i
]))
1330 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1331 lua_rawseti(L
, -2, ++j
);
1337 /** Raise a client on top of others which are on the same layer.
1338 * \param L The Lua VM state.
1343 luaA_client_raise(lua_State
*L
)
1345 client_t
**c
= luaA_checkudata(L
, 1, "client");
1350 /** Lower a client on bottom of others which are on the same layer.
1351 * \param L The Lua VM state.
1356 luaA_client_lower(lua_State
*L
)
1358 client_t
**c
= luaA_checkudata(L
, 1, "client");
1363 /** Redraw a client by unmapping and mapping it quickly.
1364 * \param L The Lua VM state.
1370 luaA_client_redraw(lua_State
*L
)
1372 client_t
**c
= luaA_checkudata(L
, 1, "client");
1374 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1375 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1377 /* Set the focus on the current window if the redraw has been
1378 performed on the window where the pointer is currently on
1379 because after the unmapping/mapping, the focus is lost */
1380 if(globalconf
.screen_focus
->client_focus
== *c
)
1381 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1382 (*c
)->win
, XCB_CURRENT_TIME
);
1387 /** Stop managing a client.
1388 * \param L The Lua VM state.
1389 * \return The number of elements pushed on stack.
1394 luaA_client_unmanage(lua_State
*L
)
1396 client_t
**c
= luaA_checkudata(L
, 1, "client");
1397 client_unmanage(*c
);
1401 /** Return client geometry.
1402 * \param L The Lua VM state.
1403 * \return The number of elements pushed on stack.
1405 * \lparam A table with new coordinates, or none.
1406 * \lreturn A table with client coordinates.
1409 luaA_client_geometry(lua_State
*L
)
1411 client_t
**c
= luaA_checkudata(L
, 1, "client");
1413 if(lua_gettop(L
) == 2)
1417 luaA_checktable(L
, 2);
1418 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1419 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1420 if(client_isfixed(*c
))
1422 geometry
.width
= (*c
)->geometry
.width
;
1423 geometry
.height
= (*c
)->geometry
.height
;
1427 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1428 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1431 client_resize(*c
, geometry
, (*c
)->size_hints_honor
);
1434 return luaA_pusharea(L
, (*c
)->geometry
);
1437 /** Client newindex.
1438 * \param L The Lua VM state.
1439 * \return The number of elements pushed on stack.
1442 luaA_client_newindex(lua_State
*L
)
1445 client_t
**c
= luaA_checkudata(L
, 1, "client");
1446 const char *buf
= luaL_checklstring(L
, 2, &len
);
1454 luaL_error(L
, "client is invalid\n");
1456 switch(a_tokenize(buf
, len
))
1459 if(globalconf
.xinerama_is_active
)
1461 i
= luaL_checknumber(L
, 3) - 1;
1462 luaA_checkscreen(i
);
1463 screen_client_moveto(*c
, i
, true, true);
1467 b
= luaA_checkboolean(L
, 3);
1468 if(b
!= (*c
)->ishidden
)
1470 client_need_arrange(*c
);
1472 client_need_arrange(*c
);
1476 luaA_deprecate(L
, "client.minimized");
1477 case A_TK_MINIMIZED
:
1478 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1480 case A_TK_FULLSCREEN
:
1481 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1483 case A_TK_MAXIMIZED_HORIZONTAL
:
1484 client_setmaxhoriz(*c
, luaA_checkboolean(L
, 3));
1486 case A_TK_MAXIMIZED_VERTICAL
:
1487 client_setmaxvert(*c
, luaA_checkboolean(L
, 3));
1490 image
= luaA_checkudata(L
, 3, "image");
1491 image_unref(&(*c
)->icon
);
1493 (*c
)->icon
= *image
;
1495 hooks_property(*c
, "icon");
1499 window_opacity_set((*c
)->win
, -1);
1502 d
= luaL_checknumber(L
, 3);
1503 if(d
>= 0 && d
<= 1)
1504 window_opacity_set((*c
)->win
, d
);
1508 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1510 case A_TK_HONORSIZEHINTS
:
1511 luaA_deprecate(L
, "size_hints_honor");
1512 case A_TK_SIZE_HINTS_HONOR
:
1513 (*c
)->size_hints_honor
= luaA_checkboolean(L
, 3);
1514 client_need_arrange(*c
);
1516 case A_TK_BORDER_WIDTH
:
1517 client_setborder(*c
, luaL_checknumber(L
, 3));
1520 client_setontop(*c
, luaA_checkboolean(L
, 3));
1522 case A_TK_BORDER_COLOR
:
1523 if((buf
= luaL_checklstring(L
, 3, &len
))
1524 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1525 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1526 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1530 titlebar_client_detach(*c
);
1533 t
= luaA_checkudata(L
, 3, "wibox");
1534 titlebar_client_attach(*c
, *t
);
1545 * \param L The Lua VM state.
1546 * \return The number of elements pushed on stack.
1548 * \lfield name The client title.
1549 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1550 * \lfield type The window type (desktop, normal, dock, …).
1551 * \lfield class The client class.
1552 * \lfield instance The client instance.
1553 * \lfield pid The client PID, if available.
1554 * \lfield role The window role, if available.
1555 * \lfield machine The machine client is running on.
1556 * \lfield icon_name The client name when iconified.
1557 * \lfield screen Client screen number.
1558 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1559 * invisible in taskbar.
1560 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1562 * \lfield icon_path Path to the icon used to identify.
1563 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1564 * \lfield border_width The client border width.
1565 * \lfield border_color The client border color.
1566 * \lfield titlebar The client titlebar.
1567 * \lfield urgent The client urgent state.
1568 * \lfield content An image representing the client window content (screenshot).
1569 * \lfield focus The focused client.
1570 * \lfield opacity The client opacity between 0 and 1.
1571 * \lfield ontop The client is on top of every other windows.
1572 * \lfield fullscreen The client is fullscreen or not.
1573 * \lfield maximized_horizontal The client is maximized horizontally or not.
1574 * \lfield maximized_vertical The client is maximized vertically or not.
1575 * \lfield transient_for Return the client the window is transient for.
1576 * \lfield group_id Identification unique to a group of windows.
1577 * \lfield leader_id Identification unique to windows spawned by the same command.
1578 * \lfield size_hints A table with size hints of the client: user_position,
1579 * user_size, program_position, program_size, etc.
1582 luaA_client_index(lua_State
*L
)
1586 client_t
**c
= luaA_checkudata(L
, 1, "client");
1587 const char *buf
= luaL_checklstring(L
, 2, &len
);
1590 xcb_get_wm_class_reply_t hint
;
1591 xcb_get_property_cookie_t prop_c
;
1592 xcb_get_property_reply_t
*prop_r
= NULL
;
1596 luaL_error(L
, "client is invalid\n");
1598 if(luaA_usemetatable(L
, 1, 2))
1601 switch(a_tokenize(buf
, len
))
1606 lua_pushstring(L
, (*c
)->name
);
1608 case A_TK_TRANSIENT_FOR
:
1609 if((*c
)->transient_for
)
1610 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1612 case A_TK_SKIP_TASKBAR
:
1613 lua_pushboolean(L
, (*c
)->skiptb
);
1616 if((image
= client_getcontent(*c
)))
1617 return luaA_image_userdata_new(L
, image
);
1622 case WINDOW_TYPE_DESKTOP
:
1623 lua_pushliteral(L
, "desktop");
1625 case WINDOW_TYPE_DOCK
:
1626 lua_pushliteral(L
, "dock");
1628 case WINDOW_TYPE_SPLASH
:
1629 lua_pushliteral(L
, "splash");
1631 case WINDOW_TYPE_DIALOG
:
1632 lua_pushliteral(L
, "dialog");
1634 case WINDOW_TYPE_MENU
:
1635 lua_pushliteral(L
, "menu");
1637 case WINDOW_TYPE_TOOLBAR
:
1638 lua_pushliteral(L
, "toolbar");
1640 case WINDOW_TYPE_UTILITY
:
1641 lua_pushliteral(L
, "utility");
1644 lua_pushliteral(L
, "normal");
1649 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1650 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1653 lua_pushstring(L
, hint
.class);
1654 xcb_get_wm_class_reply_wipe(&hint
);
1657 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1658 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1661 lua_pushstring(L
, hint
.name
);
1662 xcb_get_wm_class_reply_wipe(&hint
);
1665 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1666 WM_WINDOW_ROLE
, &value
, &slen
))
1668 lua_pushlstring(L
, value
, slen
);
1672 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1673 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1675 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1676 lua_pushnumber(L
, *(uint32_t *)data
);
1683 case A_TK_LEADER_ID
:
1684 lua_pushnumber(L
, (*c
)->leader_win
);
1687 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1688 WM_CLIENT_MACHINE
, &value
, &slen
))
1690 lua_pushlstring(L
, value
, slen
);
1693 case A_TK_ICON_NAME
:
1694 lua_pushstring(L
, (*c
)->icon_name
);
1697 lua_pushnumber(L
, 1 + (*c
)->screen
);
1700 lua_pushboolean(L
, (*c
)->ishidden
);
1703 luaA_deprecate(L
, "client.minimized");
1704 case A_TK_MINIMIZED
:
1705 lua_pushboolean(L
, (*c
)->isminimized
);
1707 case A_TK_FULLSCREEN
:
1708 lua_pushboolean(L
, (*c
)->isfullscreen
);
1712 lua_pushnumber(L
, (*c
)->group_win
);
1716 case A_TK_MAXIMIZED_HORIZONTAL
:
1717 lua_pushboolean(L
, (*c
)->ismaxhoriz
);
1719 case A_TK_MAXIMIZED_VERTICAL
:
1720 lua_pushboolean(L
, (*c
)->ismaxvert
);
1724 luaA_image_userdata_new(L
, (*c
)->icon
);
1729 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1730 lua_pushnumber(L
, d
);
1735 lua_pushboolean(L
, (*c
)->isontop
);
1738 lua_pushboolean(L
, (*c
)->issticky
);
1740 case A_TK_HONORSIZEHINTS
:
1741 luaA_deprecate(L
, "size_hints_honor");
1742 case A_TK_SIZE_HINTS_HONOR
:
1743 lua_pushboolean(L
, (*c
)->size_hints_honor
);
1745 case A_TK_BORDER_WIDTH
:
1746 lua_pushnumber(L
, (*c
)->border
);
1748 case A_TK_BORDER_COLOR
:
1749 luaA_pushcolor(L
, &(*c
)->border_color
);
1753 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1756 lua_pushboolean(L
, (*c
)->isurgent
);
1758 case A_TK_SIZE_HINTS
:
1760 const char *u_or_p
= NULL
;
1764 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1765 u_or_p
= "user_position";
1766 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1767 u_or_p
= "program_position";
1772 lua_pushnumber(L
, (*c
)->size_hints
.x
);
1773 lua_setfield(L
, -2, "x");
1774 lua_pushnumber(L
, (*c
)->size_hints
.y
);
1775 lua_setfield(L
, -2, "y");
1776 lua_setfield(L
, -2, u_or_p
);
1780 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1781 u_or_p
= "user_size";
1782 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1783 u_or_p
= "program_size";
1788 lua_pushnumber(L
, (*c
)->size_hints
.width
);
1789 lua_setfield(L
, -2, "width");
1790 lua_pushnumber(L
, (*c
)->size_hints
.height
);
1791 lua_setfield(L
, -2, "height");
1792 lua_setfield(L
, -2, u_or_p
);
1795 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1797 lua_pushnumber(L
, (*c
)->size_hints
.min_width
);
1798 lua_setfield(L
, -2, "min_width");
1799 lua_pushnumber(L
, (*c
)->size_hints
.min_height
);
1800 lua_setfield(L
, -2, "min_height");
1803 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1805 lua_pushnumber(L
, (*c
)->size_hints
.max_width
);
1806 lua_setfield(L
, -2, "max_width");
1807 lua_pushnumber(L
, (*c
)->size_hints
.max_height
);
1808 lua_setfield(L
, -2, "max_height");
1811 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1813 lua_pushnumber(L
, (*c
)->size_hints
.width_inc
);
1814 lua_setfield(L
, -2, "width_inc");
1815 lua_pushnumber(L
, (*c
)->size_hints
.height_inc
);
1816 lua_setfield(L
, -2, "height_inc");
1819 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1821 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_num
);
1822 lua_setfield(L
, -2, "min_aspect_num");
1823 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_den
);
1824 lua_setfield(L
, -2, "min_aspect_den");
1825 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_num
);
1826 lua_setfield(L
, -2, "max_aspect_num");
1827 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_den
);
1828 lua_setfield(L
, -2, "max_aspect_den");
1831 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1833 lua_pushnumber(L
, (*c
)->size_hints
.base_width
);
1834 lua_setfield(L
, -2, "base_width");
1835 lua_pushnumber(L
, (*c
)->size_hints
.base_height
);
1836 lua_setfield(L
, -2, "base_height");
1839 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1841 switch((*c
)->size_hints
.win_gravity
)
1844 lua_pushliteral(L
, "north_west");
1846 case XCB_GRAVITY_NORTH
:
1847 lua_pushliteral(L
, "north");
1849 case XCB_GRAVITY_NORTH_EAST
:
1850 lua_pushliteral(L
, "north_east");
1852 case XCB_GRAVITY_WEST
:
1853 lua_pushliteral(L
, "west");
1855 case XCB_GRAVITY_CENTER
:
1856 lua_pushliteral(L
, "center");
1858 case XCB_GRAVITY_EAST
:
1859 lua_pushliteral(L
, "east");
1861 case XCB_GRAVITY_SOUTH_WEST
:
1862 lua_pushliteral(L
, "south_west");
1864 case XCB_GRAVITY_SOUTH
:
1865 lua_pushliteral(L
, "south");
1867 case XCB_GRAVITY_SOUTH_EAST
:
1868 lua_pushliteral(L
, "south_east");
1870 case XCB_GRAVITY_STATIC
:
1871 lua_pushliteral(L
, "static");
1874 lua_setfield(L
, -2, "win_gravity");
1885 /** Get or set mouse buttons bindings for a client.
1886 * \param L The Lua VM state.
1887 * \return The number of element pushed on stack.
1890 * \lparam An array of mouse button bindings objects, or nothing.
1891 * \return The array of mouse button bindings objects of this client.
1894 luaA_client_buttons(lua_State
*L
)
1896 client_t
**client
= luaA_checkudata(L
, 1, "client");
1897 button_array_t
*buttons
= &(*client
)->buttons
;
1899 if(lua_gettop(L
) == 2)
1900 luaA_button_array_set(L
, 2, buttons
);
1902 return luaA_button_array_get(L
, buttons
);
1905 /** Get or set keys bindings for a client.
1906 * \param L The Lua VM state.
1907 * \return The number of element pushed on stack.
1910 * \lparam An array of key bindings objects, or nothing.
1911 * \return The array of key bindings objects of this client.
1914 luaA_client_keys(lua_State
*L
)
1916 client_t
**c
= luaA_checkudata(L
, 1, "client");
1917 keybindings_t
*keys
= &(*c
)->keys
;
1919 if(lua_gettop(L
) == 2)
1921 luaA_key_array_set(L
, 2, keys
);
1922 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, (*c
)->win
, XCB_BUTTON_MASK_ANY
);
1923 window_grabkeys((*c
)->win
, keys
);
1926 return luaA_key_array_get(L
, keys
);
1929 /** Send fake events to a client.
1930 * \param L The Lua VM state.
1931 * \return The number of element pushed on stack.
1934 * \param The event type: key_press, key_release, button_press, button_release
1936 * \param The detail: in case of a key event, this is the keycode to send, in
1937 * case of a button event this is the number of the button. In case of a motion
1938 * event, this is a boolean value which if true make the coordinates relatives.
1939 * \param In case of a motion event, this is the X coordinate.
1940 * \param In case of a motion event, this is the Y coordinate.
1943 luaA_client_fake_input(lua_State
*L
)
1945 if(!globalconf
.have_xtest
)
1947 luaA_warn(L
, "XTest extension is not available, cannot fake input.");
1951 client_t
**c
= luaA_checkudata(L
, 1, "client");
1953 const char *stype
= luaL_checklstring(L
, 2, &tlen
);
1954 uint8_t type
, detail
;
1957 switch(a_tokenize(stype
, tlen
))
1959 case A_TK_KEY_PRESS
:
1960 type
= XCB_KEY_PRESS
;
1961 detail
= luaL_checknumber(L
, 3); /* keycode */
1963 case A_TK_KEY_RELEASE
:
1964 type
= XCB_KEY_RELEASE
;
1965 detail
= luaL_checknumber(L
, 3); /* keycode */
1967 case A_TK_BUTTON_PRESS
:
1968 type
= XCB_BUTTON_PRESS
;
1969 detail
= luaL_checknumber(L
, 3); /* button number */
1971 case A_TK_BUTTON_RELEASE
:
1972 type
= XCB_BUTTON_RELEASE
;
1973 detail
= luaL_checknumber(L
, 3); /* button number */
1975 case A_TK_MOTION_NOTIFY
:
1976 type
= XCB_MOTION_NOTIFY
;
1977 detail
= luaA_checkboolean(L
, 3); /* relative to the current position or not */
1978 x
= luaL_checknumber(L
, 4);
1979 y
= luaL_checknumber(L
, 5);
1985 xcb_test_fake_input(globalconf
.connection
,
1996 * \param L The Lua VM state.
1997 * \return The number of pushed elements.
2000 luaA_client_module_index(lua_State
*L
)
2003 const char *buf
= luaL_checklstring(L
, 2, &len
);
2005 switch(a_tokenize(buf
, len
))
2008 if(globalconf
.screen_focus
->client_focus
)
2009 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
2020 /* Client module new index.
2021 * \param L The Lua VM state.
2022 * \return The number of pushed elements.
2025 luaA_client_module_newindex(lua_State
*L
)
2028 const char *buf
= luaL_checklstring(L
, 2, &len
);
2031 switch(a_tokenize(buf
, len
))
2034 c
= luaA_checkudata(L
, 3, "client");
2044 /** Move a client with mouse (DEPRECATED).
2045 * \param L The Lua VM state.
2048 luaA_client_mouse_move(lua_State
*L
)
2050 luaA_deprecate(L
, "awful.mouse.client.move()");
2054 /** Resize a client with mouse (DEPRECATED).
2055 * \param L The Lua VM state.
2056 * \return The number of pushed elements.
2059 luaA_client_mouse_resize(lua_State
*L
)
2061 luaA_deprecate(L
, "awful.mouse.client.resize()");
2065 const struct luaL_reg awesome_client_methods
[] =
2067 { "get", luaA_client_get
},
2068 { "__index", luaA_client_module_index
},
2069 { "__newindex", luaA_client_module_newindex
},
2072 const struct luaL_reg awesome_client_meta
[] =
2074 { "isvisible", luaA_client_isvisible
},
2075 { "geometry", luaA_client_geometry
},
2076 { "buttons", luaA_client_buttons
},
2077 { "keys", luaA_client_keys
},
2078 { "tags", luaA_client_tags
},
2079 { "kill", luaA_client_kill
},
2080 { "swap", luaA_client_swap
},
2081 { "raise", luaA_client_raise
},
2082 { "lower", luaA_client_lower
},
2083 { "redraw", luaA_client_redraw
},
2084 { "mouse_resize", luaA_client_mouse_resize
},
2085 { "mouse_move", luaA_client_mouse_move
},
2086 { "unmanage", luaA_client_unmanage
},
2087 { "fake_input", luaA_client_fake_input
},
2088 { "__index", luaA_client_index
},
2089 { "__newindex", luaA_client_newindex
},
2090 { "__eq", luaA_client_eq
},
2091 { "__gc", luaA_client_gc
},
2092 { "__tostring", luaA_client_tostring
},
2096 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80