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 /** Change the clients urgency flag.
114 * \param c The client
115 * \param urgent The new flag state
118 client_seturgent(client_t
*c
, bool urgent
)
120 if(c
->isurgent
!= urgent
)
122 xcb_get_property_cookie_t hints
=
123 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
125 c
->isurgent
= urgent
;
126 ewmh_client_update_hints(c
);
128 /* update ICCCM hints */
130 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
133 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
135 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
137 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
139 hooks_property(c
, "urgent");
143 /** Returns true if a client is tagged
144 * with one of the tags of the specified screen.
145 * \param c The client to check.
146 * \param screen Virtual screen number.
147 * \return true if the client is visible, false otherwise.
150 client_maybevisible(client_t
*c
, int screen
)
152 if(c
->screen
== screen
)
154 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
157 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
159 for(int i
= 0; i
< tags
->len
; i
++)
160 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
166 /** Return the content of a client as an image.
167 * That's just take a screenshot.
168 * \param c The client.
172 client_getcontent(client_t
*c
)
174 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
177 c
->geometries
.internal
.width
,
178 c
->geometries
.internal
.height
,
179 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
181 if(!ximage
|| ximage
->bpp
< 24)
184 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
186 for(int y
= 0; y
< ximage
->height
; y
++)
187 for(int x
= 0; x
< ximage
->width
; x
++)
189 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
190 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
193 image_t
*image
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
195 xcb_image_destroy(ximage
);
200 /** Get a client by its window.
201 * \param w The client window to find.
202 * \return A client pointer if found, NULL otherwise.
205 client_getbywin(xcb_window_t w
)
208 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
212 /** Call unfocus hook.
213 * \param c Client being unfocused
216 client_unfocus_hook(client_t
*c
)
219 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
221 luaA_client_userdata_new(globalconf
.L
, c
);
222 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
226 /** Unfocus a client.
227 * \param c The client.
230 client_unfocus(client_t
*c
)
232 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
233 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
235 /* Set focus on root window, so no events leak to the current window. */
236 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
237 root_win
, XCB_CURRENT_TIME
);
239 client_unfocus_hook(c
);
241 ewmh_update_net_active_window(c
->phys_screen
);
244 /** Ban client and move it out of the viewport.
245 * \param c The client.
248 client_ban(client_t
*c
)
252 /* Move all clients out of the physical viewport into negative coordinate space. */
253 /* They will all be put on top of each other. */
254 uint32_t request
[2] = { - (c
->geometries
.internal
.width
+ 2 * c
->border
),
255 - (c
->geometries
.internal
.height
+ 2 * c
->border
) };
257 xcb_configure_window(globalconf
.connection
, c
->win
,
258 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
261 titlebar_ban(c
->titlebar
);
265 /* All the wiboxes (may) need to be repositioned. */
266 if(client_hasstrut(c
))
267 wibox_update_positions();
270 /* Wait until the last moment to take away the focus from the window. */
271 if (globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
275 /** Give focus to client, or to first client if client is NULL.
276 * \param c The client or NULL.
277 * \return True if a window (even root) has received focus, false otherwise.
280 client_focus(client_t
*c
)
282 if(!client_maybevisible(c
, c
->screen
))
285 /* Input Model: No Input */
286 if (!window_hasproto(c
->win
, WM_TAKE_FOCUS
) && c
->nofocus
)
289 /* unfocus current selected client
290 * We don't really need to unfocus here,
291 * because client already received FocusOut event.
292 * What we need to do is call unfocus hook, to
293 * inform lua script, about this event.
295 if(globalconf
.screen_focus
->client_focus
296 && c
!= globalconf
.screen_focus
->client_focus
)
297 client_unfocus_hook(globalconf
.screen_focus
->client_focus
);
301 client_setminimized(c
, false);
303 /* unban the client before focusing or it will fail */
306 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
307 globalconf
.screen_focus
->client_focus
= c
;
309 /* Input Models: Passive, Locally Active */
310 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
311 c
->win
, XCB_CURRENT_TIME
);
313 /* TODO: Currently we don't handle correctly globally active input model
314 * One fix I know of, is we should handle FocusIn and FocusOut events for windows,
315 * and use WM_TAKE_FOCUS client message.
318 /* Some layouts use focused client differently, so call them back.
319 * And anyway, we have maybe unhidden */
320 client_need_arrange(c
);
323 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
325 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
326 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
329 /* according to EWMH, we have to remove the urgent state from a client */
330 client_seturgent(c
, false);
332 ewmh_update_net_active_window(c
->phys_screen
);
335 /** Stack a window below.
336 * \param c The client.
337 * \param previous The previous window on the stack.
338 * \param return The next-previous!
341 client_stack_above(client_t
*c
, xcb_window_t previous
)
343 uint32_t config_win_vals
[2];
345 config_win_vals
[0] = previous
;
346 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
348 xcb_configure_window(globalconf
.connection
, c
->win
,
349 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
352 config_win_vals
[0] = c
->win
;
356 xcb_configure_window(globalconf
.connection
,
357 c
->titlebar
->sw
.window
,
358 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
360 previous
= c
->titlebar
->sw
.window
;
365 /* stack transient window on top of their parents */
366 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
367 node
; node
= node
->prev
)
368 if(node
->client
->transient_for
== c
)
369 previous
= client_stack_above(node
->client
, previous
);
374 /** Stacking layout layers */
377 /** This one is a special layer */
388 /** Get the real layer of a client according to its attribute (fullscreen, …)
389 * \param c The client.
390 * \return The real layer.
393 client_layer_translator(client_t
*c
)
395 /* first deal with user set attributes */
398 else if(c
->isfullscreen
)
399 return LAYER_FULLSCREEN
;
405 /* check for transient attr */
409 /* then deal with windows type */
412 case WINDOW_TYPE_DOCK
:
414 case WINDOW_TYPE_DESKTOP
:
415 return LAYER_DESKTOP
;
416 case WINDOW_TYPE_DIALOG
:
417 case WINDOW_TYPE_MENU
:
418 case WINDOW_TYPE_TOOLBAR
:
419 case WINDOW_TYPE_UTILITY
:
429 * \todo It might be worth stopping to restack everyone and only stack `c'
430 * relatively to the first matching in the list.
435 uint32_t config_win_vals
[2];
436 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
440 config_win_vals
[0] = XCB_NONE
;
441 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
443 /* stack desktop windows */
444 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
445 for(node
= last
; node
; node
= node
->prev
)
446 if(client_layer_translator(node
->client
) == layer
)
447 config_win_vals
[0] = client_stack_above(node
->client
,
450 /* first stack not ontop wibox window */
451 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
452 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
454 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
457 xcb_configure_window(globalconf
.connection
,
459 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
461 config_win_vals
[0] = sb
->sw
.window
;
465 /* then stack clients */
466 for(layer
= LAYER_BELOW
; layer
< LAYER_OUTOFSPACE
; layer
++)
467 for(node
= last
; node
; node
= node
->prev
)
468 if(client_layer_translator(node
->client
) == layer
)
469 config_win_vals
[0] = client_stack_above(node
->client
,
472 /* then stack ontop wibox window */
473 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
474 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
476 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
479 xcb_configure_window(globalconf
.connection
,
481 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
483 config_win_vals
[0] = sb
->sw
.window
;
488 /** Manage a new client.
489 * \param w The window.
490 * \param wgeom Window geometry.
491 * \param phys_screen Physical screen number.
492 * \param startup True if we are managing at startup time.
495 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
497 xcb_get_property_cookie_t ewmh_icon_cookie
;
498 client_t
*c
, *tc
= NULL
;
501 const uint32_t select_input_val
[] =
503 XCB_EVENT_MASK_STRUCTURE_NOTIFY
504 | XCB_EVENT_MASK_PROPERTY_CHANGE
505 | XCB_EVENT_MASK_ENTER_WINDOW
506 | XCB_EVENT_MASK_LEAVE_WINDOW
510 if(systray_iskdedockapp(w
))
512 systray_request_handle(w
, phys_screen
, NULL
);
516 /* Send request to get NET_WM_ICON property as soon as possible... */
517 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
518 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
519 c
= p_new(client_t
, 1);
521 screen
= c
->screen
= screen_getbycoord(phys_screen
, wgeom
->x
, wgeom
->y
);
523 c
->phys_screen
= phys_screen
;
527 c
->geometry
.x
= wgeom
->x
;
528 c
->geometry
.y
= wgeom
->y
;
529 /* Border will be added later. */
530 c
->geometry
.width
= wgeom
->width
;
531 c
->geometry
.height
= wgeom
->height
;
532 /* Also set internal geometry (client_ban() needs it). */
533 c
->geometries
.internal
.x
= wgeom
->x
;
534 c
->geometries
.internal
.y
= wgeom
->y
;
535 c
->geometries
.internal
.width
= wgeom
->width
;
536 c
->geometries
.internal
.height
= wgeom
->height
;
537 client_setborder(c
, wgeom
->border_width
);
538 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
539 c
->icon
= image_ref(&icon
);
541 /* we honor size hints by default */
542 c
->size_hints_honor
= true;
545 property_update_wm_normal_hints(c
, NULL
);
546 property_update_wm_hints(c
, NULL
);
547 property_update_wm_transient_for(c
, NULL
);
548 property_update_wm_client_leader(c
, NULL
);
550 /* Recursively find the parent. */
551 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
552 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
555 /* Try to load props */
556 client_loadprops(c
, &globalconf
.screens
[screen
]);
558 /* Then check clients hints */
559 ewmh_client_check_hints(c
);
561 /* move client to screen, but do not tag it */
562 screen_client_moveto(c
, screen
, false, true);
564 /* Push client in client list */
565 client_list_push(&globalconf
.clients
, client_ref(&c
));
567 /* Push client in stack */
570 /* update window title */
571 property_update_wm_name(c
);
572 property_update_wm_icon_name(c
);
575 ewmh_process_client_strut(c
, NULL
);
577 ewmh_update_net_client_list(c
->phys_screen
);
579 /* Always stay in NORMAL_STATE. Even though iconified seems more
580 * appropriate sometimes. The only possible loss is that clients not using
581 * visibility events may continue to proces data (when banned).
582 * Without any exposes or other events the cost should be fairly limited though.
584 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
585 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
587 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
588 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
590 * "Once a client's window has left the Withdrawn state, the window will be mapped
591 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
593 * At this stage it's just safer to keep it in normal state and avoid confusion.
595 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
597 /* Move window outside the viewport before mapping it. */
599 xcb_map_window(globalconf
.connection
, c
->win
);
601 /* Call hook to notify list change */
602 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
603 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
606 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
608 luaA_client_userdata_new(globalconf
.L
, c
);
609 lua_pushboolean(globalconf
.L
, startup
);
610 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
614 /** Compute client geometry with respect to its geometry hints.
615 * \param c The client.
616 * \param geometry The geometry that the client might receive.
617 * \return The geometry the client must take respecting its hints.
620 client_geometry_hints(client_t
*c
, area_t geometry
)
622 int32_t basew
, baseh
, minw
, minh
;
624 /* base size is substituted with min size if not specified */
625 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
627 basew
= c
->size_hints
.base_width
;
628 baseh
= c
->size_hints
.base_height
;
630 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
632 basew
= c
->size_hints
.min_width
;
633 baseh
= c
->size_hints
.min_height
;
638 /* min size is substituted with base size if not specified */
639 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
641 minw
= c
->size_hints
.min_width
;
642 minh
= c
->size_hints
.min_height
;
644 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
646 minw
= c
->size_hints
.base_width
;
647 minh
= c
->size_hints
.base_height
;
652 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
653 && c
->size_hints
.min_aspect_num
> 0
654 && c
->size_hints
.min_aspect_den
> 0
655 && geometry
.height
- baseh
> 0
656 && geometry
.width
- basew
> 0)
658 double dx
= (double) (geometry
.width
- basew
);
659 double dy
= (double) (geometry
.height
- baseh
);
660 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
661 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
662 double ratio
= dx
/ dy
;
663 if(max
> 0 && min
> 0 && ratio
> 0)
667 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
669 geometry
.width
= (int) dx
+ basew
;
670 geometry
.height
= (int) dy
+ baseh
;
674 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
676 geometry
.width
= (int) dx
+ basew
;
677 geometry
.height
= (int) dy
+ baseh
;
683 geometry
.width
= MAX(geometry
.width
, minw
);
685 geometry
.height
= MAX(geometry
.height
, minh
);
687 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
689 if(c
->size_hints
.max_width
)
690 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
691 if(c
->size_hints
.max_height
)
692 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
695 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
696 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
698 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
699 unsigned_subtract(t1
, basew
);
700 unsigned_subtract(t2
, baseh
);
701 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
702 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
708 /** Resize client window.
709 * The sizse given as parameters are with titlebar and borders!
710 * \param c Client to resize.
711 * \param geometry New window geometry.
712 * \param hints Use size hints.
713 * \return true if an actual resize occurred.
716 client_resize(client_t
*c
, area_t geometry
, bool hints
)
719 area_t geometry_internal
;
722 /* offscreen appearance fixes */
723 area
= display_area_get(c
->phys_screen
, NULL
,
724 &globalconf
.screens
[c
->screen
].padding
);
726 if(geometry
.x
> area
.width
)
727 geometry
.x
= area
.width
- geometry
.width
;
728 if(geometry
.y
> area
.height
)
729 geometry
.y
= area
.height
- geometry
.height
;
730 if(geometry
.x
+ geometry
.width
< 0)
732 if(geometry
.y
+ geometry
.height
< 0)
735 /* Real client geometry, please keep it contained to C code at the very least. */
736 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
739 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
741 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
744 /* Also let client hints propegate to the "official" geometry. */
745 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
747 if(c
->geometries
.internal
.x
!= geometry_internal
.x
748 || c
->geometries
.internal
.y
!= geometry_internal
.y
749 || c
->geometries
.internal
.width
!= geometry_internal
.width
750 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
752 new_screen
= screen_getbycoord(c
->screen
, geometry_internal
.x
, geometry_internal
.y
);
754 /* Values to configure a window is an array where values are
755 * stored according to 'value_mask' */
758 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
759 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
760 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
761 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
763 /* Also store geometry including border and titlebar. */
764 c
->geometry
= geometry
;
766 titlebar_update_geometry(c
);
768 /* The idea is to give a client a resize even when banned. */
769 /* We just have to move the (x,y) to keep it out of the viewport. */
770 /* This at least doesn't break expectations about events. */
773 geometry_internal
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
774 geometry_internal
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
777 xcb_configure_window(globalconf
.connection
, c
->win
,
778 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
779 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
781 window_configure(c
->win
, geometry_internal
, c
->border
);
783 screen_client_moveto(c
, new_screen
, true, false);
786 hooks_property(c
, "geometry");
794 /** Set a client minimized, or not.
795 * \param c The client.
796 * \param s Set or not the client minimized.
799 client_setminimized(client_t
*c
, bool s
)
801 if(c
->isminimized
!= s
)
803 client_need_arrange(c
);
805 client_need_arrange(c
);
806 ewmh_client_update_hints(c
);
808 hooks_property(c
, "minimized");
812 /** Set a client sticky, or not.
813 * \param c The client.
814 * \param s Set or not the client sticky.
817 client_setsticky(client_t
*c
, bool s
)
821 client_need_arrange(c
);
823 client_need_arrange(c
);
824 ewmh_client_update_hints(c
);
825 hooks_property(c
, "sticky");
829 /** Set a client fullscreen, or not.
830 * \param c The client.
831 * \param s Set or not the client fullscreen.
834 client_setfullscreen(client_t
*c
, bool s
)
836 if(c
->isfullscreen
!= s
)
840 /* become fullscreen! */
841 if((c
->isfullscreen
= s
))
843 /* remove any max state */
844 client_setmaxhoriz(c
, false);
845 client_setmaxvert(c
, false);
846 /* You can only be part of one of the special layers. */
847 client_setbelow(c
, false);
848 client_setabove(c
, false);
849 client_setontop(c
, false);
851 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
852 c
->geometries
.fullscreen
= c
->geometry
;
853 c
->border_fs
= c
->border
;
854 client_setborder(c
, 0);
858 geometry
= c
->geometries
.fullscreen
;
859 client_setborder(c
, c
->border_fs
);
861 client_resize(c
, geometry
, false);
862 client_need_arrange(c
);
864 xcb_change_property(globalconf
.connection
,
865 XCB_PROP_MODE_REPLACE
,
866 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
868 ewmh_client_update_hints(c
);
869 hooks_property(c
, "fullscreen");
873 /** Set a client horizontally maximized.
874 * \param c The client.
875 * \param s The maximized status.
878 client_setmaxhoriz(client_t
*c
, bool s
)
880 if(c
->ismaxhoriz
!= s
)
884 if((c
->ismaxhoriz
= s
))
886 /* remove fullscreen mode */
887 client_setfullscreen(c
, false);
889 geometry
= screen_area_get(c
->screen
,
890 &globalconf
.screens
[c
->screen
].wiboxes
,
891 &globalconf
.screens
[c
->screen
].padding
,
893 geometry
.y
= c
->geometry
.y
;
894 geometry
.height
= c
->geometry
.height
;
895 c
->geometries
.max
.x
= c
->geometry
.x
;
896 c
->geometries
.max
.width
= c
->geometry
.width
;
900 geometry
= c
->geometry
;
901 geometry
.x
= c
->geometries
.max
.x
;
902 geometry
.width
= c
->geometries
.max
.width
;
905 client_resize(c
, geometry
, c
->size_hints_honor
);
906 client_need_arrange(c
);
908 ewmh_client_update_hints(c
);
909 hooks_property(c
, "maximized_horizontal");
913 /** Set a client vertically maximized.
914 * \param c The client.
915 * \param s The maximized status.
918 client_setmaxvert(client_t
*c
, bool s
)
920 if(c
->ismaxvert
!= s
)
924 if((c
->ismaxvert
= s
))
926 /* remove fullscreen mode */
927 client_setfullscreen(c
, false);
929 geometry
= screen_area_get(c
->screen
,
930 &globalconf
.screens
[c
->screen
].wiboxes
,
931 &globalconf
.screens
[c
->screen
].padding
,
933 geometry
.x
= c
->geometry
.x
;
934 geometry
.width
= c
->geometry
.width
;
935 c
->geometries
.max
.y
= c
->geometry
.y
;
936 c
->geometries
.max
.height
= c
->geometry
.height
;
940 geometry
= c
->geometry
;
941 geometry
.y
= c
->geometries
.max
.y
;
942 geometry
.height
= c
->geometries
.max
.height
;
945 client_resize(c
, geometry
, c
->size_hints_honor
);
946 client_need_arrange(c
);
948 ewmh_client_update_hints(c
);
949 hooks_property(c
, "maximized_vertical");
953 /** Set a client above, or not.
954 * \param c The client.
955 * \param s Set or not the client above.
958 client_setabove(client_t
*c
, bool s
)
962 /* You can only be part of one of the special layers. */
965 client_setbelow(c
, false);
966 client_setontop(c
, false);
967 client_setfullscreen(c
, false);
971 ewmh_client_update_hints(c
);
973 hooks_property(c
, "above");
977 /** Set a client below, or not.
978 * \param c The client.
979 * \param s Set or not the client below.
982 client_setbelow(client_t
*c
, bool s
)
986 /* You can only be part of one of the special layers. */
989 client_setabove(c
, false);
990 client_setontop(c
, false);
991 client_setfullscreen(c
, false);
995 ewmh_client_update_hints(c
);
997 hooks_property(c
, "below");
1001 /** Set a client modal, or not.
1002 * \param c The client.
1003 * \param s Set or not the client moda.
1006 client_setmodal(client_t
*c
, bool s
)
1012 ewmh_client_update_hints(c
);
1014 hooks_property(c
, "modal");
1018 /** Set a client ontop, or not.
1019 * \param c The client.
1020 * \param s Set or not the client moda.
1023 client_setontop(client_t
*c
, bool s
)
1027 /* You can only be part of one of the special layers. */
1030 client_setabove(c
, false);
1031 client_setbelow(c
, false);
1032 client_setfullscreen(c
, false);
1037 hooks_property(c
, "ontop");
1041 /** Save client properties as an X property.
1042 * \param c The client.
1045 client_saveprops_tags(client_t
*c
)
1047 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1048 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
1051 for(i
= 0; i
< tags
->len
; i
++)
1052 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
1054 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
1057 /** Unban a client and move it back into the viewport.
1058 * \param c The client.
1061 client_unban(client_t
*c
)
1065 /* Move the client back where it belongs. */
1066 uint32_t request
[] = { c
->geometries
.internal
.x
,
1067 c
->geometries
.internal
.y
,
1068 c
->geometries
.internal
.width
,
1069 c
->geometries
.internal
.height
};
1071 xcb_configure_window(globalconf
.connection
, c
->win
,
1073 | XCB_CONFIG_WINDOW_Y
1074 | XCB_CONFIG_WINDOW_WIDTH
1075 | XCB_CONFIG_WINDOW_HEIGHT
,
1077 window_configure(c
->win
, c
->geometries
.internal
, c
->border
);
1079 /* Do this manually because the system doesn't know we moved the toolbar.
1080 * Note that !isvisible titlebars are unmapped and for fullscreen it'll
1081 * end up offscreen anyway. */
1084 simple_window_t
*sw
= &c
->titlebar
->sw
;
1085 /* All resizing is done, so only move now. */
1086 request
[0] = sw
->geometry
.x
;
1087 request
[1] = sw
->geometry
.y
;
1089 xcb_configure_window(globalconf
.connection
, sw
->window
,
1090 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
1094 c
->isbanned
= false;
1096 /* All the wiboxes (may) need to be repositioned. */
1097 if(client_hasstrut(c
))
1098 wibox_update_positions();
1102 /** Unmanage a client.
1103 * \param c The client.
1106 client_unmanage(client_t
*c
)
1108 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1110 /* Reset transient_for attributes of widows that maybe refering to us */
1111 for(client_t
*tc
= globalconf
.clients
; tc
; tc
= tc
->next
)
1112 if(tc
->transient_for
== c
)
1113 tc
->transient_for
= NULL
;
1115 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
1118 /* remove client everywhere */
1119 client_list_detach(&globalconf
.clients
, c
);
1120 stack_client_delete(c
);
1121 for(int i
= 0; i
< tags
->len
; i
++)
1122 untag_client(c
, tags
->tab
[i
]);
1125 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1127 luaA_client_userdata_new(globalconf
.L
, c
);
1128 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1131 /* Call hook to notify list change */
1132 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1133 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1135 /* The server grab construct avoids race conditions. */
1136 xcb_grab_server(globalconf
.connection
);
1138 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1139 XCB_BUTTON_MASK_ANY
);
1140 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1142 xcb_flush(globalconf
.connection
);
1143 xcb_ungrab_server(globalconf
.connection
);
1145 titlebar_client_detach(c
);
1147 ewmh_update_net_client_list(c
->phys_screen
);
1149 /* delete properties */
1150 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
1151 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
1153 /* All the wiboxes (may) need to be repositioned. */
1154 if(client_hasstrut(c
))
1155 wibox_update_positions();
1157 /* set client as invalid */
1163 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1165 * \param c The client to kill.
1168 client_kill(client_t
*c
)
1170 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1172 xcb_client_message_event_t ev
;
1174 /* Initialize all of event's fields first */
1177 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1180 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1181 ev
.type
= WM_PROTOCOLS
;
1182 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1184 xcb_send_event(globalconf
.connection
, false, c
->win
,
1185 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1188 xcb_kill_client(globalconf
.connection
, c
->win
);
1191 /** Get all clients into a table.
1192 * \param L The Lua VM state.
1193 * \return The number of elements pushed on stack.
1195 * \lparam An optional screen nunmber.
1196 * \lreturn A table with all clients.
1199 luaA_client_get(lua_State
*L
)
1204 screen
= luaL_optnumber(L
, 1, 0) - 1;
1208 if(screen
== SCREEN_UNDEF
)
1209 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1211 luaA_client_userdata_new(globalconf
.L
, c
);
1212 lua_rawseti(L
, -2, i
++);
1216 luaA_checkscreen(screen
);
1217 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1218 if(c
->screen
== screen
)
1220 luaA_client_userdata_new(globalconf
.L
, c
);
1221 lua_rawseti(L
, -2, i
++);
1228 /** Check if a client is visible on its screen.
1229 * \param L The Lua VM state.
1230 * \return The number of elements pushed on stack.
1233 * \lreturn A boolean value, true if the client is visible, false otherwise.
1236 luaA_client_isvisible(lua_State
*L
)
1238 client_t
**c
= luaA_checkudata(L
, 1, "client");
1239 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
1243 /** Set client border width.
1244 * \param c The client.
1245 * \param width The border width.
1248 client_setborder(client_t
*c
, int width
)
1252 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1253 || c
->type
== WINDOW_TYPE_SPLASH
1254 || c
->type
== WINDOW_TYPE_DESKTOP
1255 || c
->isfullscreen
))
1258 if(width
== c
->border
|| width
< 0)
1261 /* Update geometry with the new border. */
1262 c
->geometry
.width
-= c
->border
;
1263 c
->geometry
.height
-= c
->border
;
1266 xcb_configure_window(globalconf
.connection
, c
->win
,
1267 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1269 c
->geometry
.width
+= c
->border
;
1270 c
->geometry
.height
+= c
->border
;
1271 /* Tiled clients will be resized by the layout functions. */
1272 client_need_arrange(c
);
1274 /* Changing border size also affects the size of the titlebar. */
1276 titlebar_update_geometry(c
);
1278 hooks_property(c
, "border_width");
1282 * \param L The Lua VM state.
1288 luaA_client_kill(lua_State
*L
)
1290 client_t
**c
= luaA_checkudata(L
, 1, "client");
1295 /** Swap a client with another one.
1296 * \param L The Lua VM state.
1299 * \lparam A client to swap with.
1302 luaA_client_swap(lua_State
*L
)
1304 client_t
**c
= luaA_checkudata(L
, 1, "client");
1305 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1309 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1310 client_need_arrange(*c
);
1311 client_need_arrange(*swap
);
1313 /* Call hook to notify list change */
1314 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1315 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1321 /** Access or set the client tags.
1322 * \param L The Lua VM state.
1323 * \return The number of elements pushed on stack.
1324 * \lparam A table with tags to set, or none to get the current tags table.
1325 * \return The clients tag.
1328 luaA_client_tags(lua_State
*L
)
1332 client_t
**c
= luaA_checkudata(L
, 1, "client");
1335 if(lua_gettop(L
) == 2)
1337 luaA_checktable(L
, 2);
1338 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1339 for(int i
= 0; i
< tags
->len
; i
++)
1340 untag_client(*c
, tags
->tab
[i
]);
1342 while(lua_next(L
, 2))
1344 tag
= luaA_checkudata(L
, -1, "tag");
1345 tag_client(*c
, *tag
);
1351 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1353 for(int i
= 0; i
< tags
->len
; i
++)
1354 if(is_client_tagged(*c
, tags
->tab
[i
]))
1356 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1357 lua_rawseti(L
, -2, ++j
);
1363 /** Raise a client on top of others which are on the same layer.
1364 * \param L The Lua VM state.
1369 luaA_client_raise(lua_State
*L
)
1371 client_t
**c
= luaA_checkudata(L
, 1, "client");
1376 /** Lower a client on bottom of others which are on the same layer.
1377 * \param L The Lua VM state.
1382 luaA_client_lower(lua_State
*L
)
1384 client_t
**c
= luaA_checkudata(L
, 1, "client");
1389 /** Redraw a client by unmapping and mapping it quickly.
1390 * \param L The Lua VM state.
1396 luaA_client_redraw(lua_State
*L
)
1398 client_t
**c
= luaA_checkudata(L
, 1, "client");
1400 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1401 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1403 /* Set the focus on the current window if the redraw has been
1404 performed on the window where the pointer is currently on
1405 because after the unmapping/mapping, the focus is lost */
1406 if(globalconf
.screen_focus
->client_focus
== *c
)
1412 /** Stop managing a client.
1413 * \param L The Lua VM state.
1414 * \return The number of elements pushed on stack.
1419 luaA_client_unmanage(lua_State
*L
)
1421 client_t
**c
= luaA_checkudata(L
, 1, "client");
1422 client_unmanage(*c
);
1426 /** Return client geometry.
1427 * \param L The Lua VM state.
1428 * \return The number of elements pushed on stack.
1430 * \lparam A table with new coordinates, or none.
1431 * \lreturn A table with client coordinates.
1434 luaA_client_geometry(lua_State
*L
)
1436 client_t
**c
= luaA_checkudata(L
, 1, "client");
1438 if(lua_gettop(L
) == 2)
1442 luaA_checktable(L
, 2);
1443 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1444 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1445 if(client_isfixed(*c
))
1447 geometry
.width
= (*c
)->geometry
.width
;
1448 geometry
.height
= (*c
)->geometry
.height
;
1452 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1453 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1456 client_resize(*c
, geometry
, (*c
)->size_hints_honor
);
1459 return luaA_pusharea(L
, (*c
)->geometry
);
1462 /** Push a strut type to a table on stack.
1463 * \param L The Lua VM state.
1464 * \param struts The struts to push.
1465 * \return The number of elements pushed on stack.
1468 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1471 lua_pushnumber(L
, struts
.left
);
1472 lua_setfield(L
, -2, "left");
1473 lua_pushnumber(L
, struts
.right
);
1474 lua_setfield(L
, -2, "right");
1475 lua_pushnumber(L
, struts
.top
);
1476 lua_setfield(L
, -2, "top");
1477 lua_pushnumber(L
, struts
.bottom
);
1478 lua_setfield(L
, -2, "bottom");
1482 /** Return client struts (reserved space at the edge of the screen).
1483 * \param L The Lua VM state.
1484 * \return The number of elements pushed on stack.
1486 * \lparam A table with new strut values, or none.
1487 * \lreturn A table with strut values.
1490 luaA_client_struts(lua_State
*L
)
1492 client_t
**c
= luaA_checkudata(L
, 1, "client");
1494 if(lua_gettop(L
) == 2)
1497 area_t screen_area
= display_area_get((*c
)->phys_screen
, NULL
, NULL
);
1499 struts
.left
= luaA_getopt_number(L
, 2, "left", (*c
)->strut
.left
);
1500 struts
.right
= luaA_getopt_number(L
, 2, "right", (*c
)->strut
.right
);
1501 struts
.top
= luaA_getopt_number(L
, 2, "top", (*c
)->strut
.top
);
1502 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", (*c
)->strut
.bottom
);
1504 if (struts
.left
!= (*c
)->strut
.left
|| struts
.right
!= (*c
)->strut
.right
||
1505 struts
.top
!= (*c
)->strut
.top
|| struts
.bottom
!= (*c
)->strut
.bottom
) {
1506 /* Struts are not so well defined in the context of xinerama. So we just
1507 * give the entire root window and let the window manager decide. */
1508 struts
.left_start_y
= 0;
1509 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1510 struts
.right_start_y
= 0;
1511 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1512 struts
.top_start_x
= 0;
1513 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1514 struts
.bottom_start_x
= 0;
1515 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1517 (*c
)->strut
= struts
;
1519 ewmh_update_client_strut((*c
));
1521 client_need_arrange((*c
));
1522 /* All the wiboxes (may) need to be repositioned. */
1523 wibox_update_positions();
1527 return luaA_pushstruts(L
, (*c
)->strut
);
1530 /** Client newindex.
1531 * \param L The Lua VM state.
1532 * \return The number of elements pushed on stack.
1535 luaA_client_newindex(lua_State
*L
)
1538 client_t
**c
= luaA_checkudata(L
, 1, "client");
1539 const char *buf
= luaL_checklstring(L
, 2, &len
);
1547 luaL_error(L
, "client is invalid\n");
1549 switch(a_tokenize(buf
, len
))
1552 if(globalconf
.xinerama_is_active
)
1554 i
= luaL_checknumber(L
, 3) - 1;
1555 luaA_checkscreen(i
);
1556 screen_client_moveto(*c
, i
, true, true);
1560 b
= luaA_checkboolean(L
, 3);
1561 if(b
!= (*c
)->ishidden
)
1563 client_need_arrange(*c
);
1565 client_need_arrange(*c
);
1569 luaA_deprecate(L
, "client.minimized");
1570 case A_TK_MINIMIZED
:
1571 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1573 case A_TK_FULLSCREEN
:
1574 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1576 case A_TK_MAXIMIZED_HORIZONTAL
:
1577 client_setmaxhoriz(*c
, luaA_checkboolean(L
, 3));
1579 case A_TK_MAXIMIZED_VERTICAL
:
1580 client_setmaxvert(*c
, luaA_checkboolean(L
, 3));
1583 image
= luaA_checkudata(L
, 3, "image");
1584 image_unref(&(*c
)->icon
);
1586 (*c
)->icon
= *image
;
1588 hooks_property(*c
, "icon");
1592 window_opacity_set((*c
)->win
, -1);
1595 d
= luaL_checknumber(L
, 3);
1596 if(d
>= 0 && d
<= 1)
1597 window_opacity_set((*c
)->win
, d
);
1601 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1603 case A_TK_HONORSIZEHINTS
:
1604 luaA_deprecate(L
, "size_hints_honor");
1605 case A_TK_SIZE_HINTS_HONOR
:
1606 (*c
)->size_hints_honor
= luaA_checkboolean(L
, 3);
1607 client_need_arrange(*c
);
1609 case A_TK_BORDER_WIDTH
:
1610 client_setborder(*c
, luaL_checknumber(L
, 3));
1613 client_setontop(*c
, luaA_checkboolean(L
, 3));
1616 client_setabove(*c
, luaA_checkboolean(L
, 3));
1619 client_setbelow(*c
, luaA_checkboolean(L
, 3));
1621 case A_TK_BORDER_COLOR
:
1622 if((buf
= luaL_checklstring(L
, 3, &len
))
1623 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1624 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1625 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1629 titlebar_client_detach(*c
);
1632 t
= luaA_checkudata(L
, 3, "wibox");
1633 titlebar_client_attach(*c
, *t
);
1644 * \param L The Lua VM state.
1645 * \return The number of elements pushed on stack.
1647 * \lfield name The client title.
1648 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1649 * \lfield type The window type (desktop, normal, dock, …).
1650 * \lfield class The client class.
1651 * \lfield instance The client instance.
1652 * \lfield pid The client PID, if available.
1653 * \lfield role The window role, if available.
1654 * \lfield machine The machine client is running on.
1655 * \lfield icon_name The client name when iconified.
1656 * \lfield screen Client screen number.
1657 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1658 * invisible in taskbar.
1659 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1661 * \lfield icon_path Path to the icon used to identify.
1662 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1663 * \lfield border_width The client border width.
1664 * \lfield border_color The client border color.
1665 * \lfield titlebar The client titlebar.
1666 * \lfield urgent The client urgent state.
1667 * \lfield content An image representing the client window content (screenshot).
1668 * \lfield focus The focused client.
1669 * \lfield opacity The client opacity between 0 and 1.
1670 * \lfield ontop The client is on top of every other windows.
1671 * \lfield above The client is above normal windows.
1672 * \lfield below The client is below normal windows.
1673 * \lfield fullscreen The client is fullscreen or not.
1674 * \lfield maximized_horizontal The client is maximized horizontally or not.
1675 * \lfield maximized_vertical The client is maximized vertically or not.
1676 * \lfield transient_for Return the client the window is transient for.
1677 * \lfield group_id Identification unique to a group of windows.
1678 * \lfield leader_id Identification unique to windows spawned by the same command.
1679 * \lfield size_hints A table with size hints of the client: user_position,
1680 * user_size, program_position, program_size, etc.
1683 luaA_client_index(lua_State
*L
)
1687 client_t
**c
= luaA_checkudata(L
, 1, "client");
1688 const char *buf
= luaL_checklstring(L
, 2, &len
);
1691 xcb_get_wm_class_reply_t hint
;
1692 xcb_get_property_cookie_t prop_c
;
1693 xcb_get_property_reply_t
*prop_r
= NULL
;
1697 luaL_error(L
, "client is invalid\n");
1699 if(luaA_usemetatable(L
, 1, 2))
1702 switch(a_tokenize(buf
, len
))
1707 lua_pushstring(L
, (*c
)->name
);
1709 case A_TK_TRANSIENT_FOR
:
1710 if((*c
)->transient_for
)
1711 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1713 case A_TK_SKIP_TASKBAR
:
1714 lua_pushboolean(L
, (*c
)->skiptb
);
1717 if((image
= client_getcontent(*c
)))
1718 return luaA_image_userdata_new(L
, image
);
1723 case WINDOW_TYPE_DESKTOP
:
1724 lua_pushliteral(L
, "desktop");
1726 case WINDOW_TYPE_DOCK
:
1727 lua_pushliteral(L
, "dock");
1729 case WINDOW_TYPE_SPLASH
:
1730 lua_pushliteral(L
, "splash");
1732 case WINDOW_TYPE_DIALOG
:
1733 lua_pushliteral(L
, "dialog");
1735 case WINDOW_TYPE_MENU
:
1736 lua_pushliteral(L
, "menu");
1738 case WINDOW_TYPE_TOOLBAR
:
1739 lua_pushliteral(L
, "toolbar");
1741 case WINDOW_TYPE_UTILITY
:
1742 lua_pushliteral(L
, "utility");
1744 case WINDOW_TYPE_DROPDOWN_MENU
:
1745 lua_pushliteral(L
, "dropdown_menu");
1747 case WINDOW_TYPE_POPUP_MENU
:
1748 lua_pushliteral(L
, "popup_menu");
1750 case WINDOW_TYPE_TOOLTIP
:
1751 lua_pushliteral(L
, "tooltip");
1753 case WINDOW_TYPE_NOTIFICATION
:
1754 lua_pushliteral(L
, "notification");
1756 case WINDOW_TYPE_COMBO
:
1757 lua_pushliteral(L
, "combo");
1759 case WINDOW_TYPE_DND
:
1760 lua_pushliteral(L
, "dnd");
1762 case WINDOW_TYPE_NORMAL
:
1763 lua_pushliteral(L
, "normal");
1768 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1769 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1772 lua_pushstring(L
, hint
.class_name
);
1773 xcb_get_wm_class_reply_wipe(&hint
);
1776 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1777 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1780 lua_pushstring(L
, hint
.instance_name
);
1781 xcb_get_wm_class_reply_wipe(&hint
);
1784 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1785 WM_WINDOW_ROLE
, &value
, &slen
))
1787 lua_pushlstring(L
, value
, slen
);
1791 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1792 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1794 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1795 lua_pushnumber(L
, *(uint32_t *)data
);
1802 case A_TK_LEADER_ID
:
1803 lua_pushnumber(L
, (*c
)->leader_win
);
1806 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1807 WM_CLIENT_MACHINE
, &value
, &slen
))
1809 lua_pushlstring(L
, value
, slen
);
1812 case A_TK_ICON_NAME
:
1813 lua_pushstring(L
, (*c
)->icon_name
);
1816 lua_pushnumber(L
, 1 + (*c
)->screen
);
1819 lua_pushboolean(L
, (*c
)->ishidden
);
1822 luaA_deprecate(L
, "client.minimized");
1823 case A_TK_MINIMIZED
:
1824 lua_pushboolean(L
, (*c
)->isminimized
);
1826 case A_TK_FULLSCREEN
:
1827 lua_pushboolean(L
, (*c
)->isfullscreen
);
1831 lua_pushnumber(L
, (*c
)->group_win
);
1835 case A_TK_MAXIMIZED_HORIZONTAL
:
1836 lua_pushboolean(L
, (*c
)->ismaxhoriz
);
1838 case A_TK_MAXIMIZED_VERTICAL
:
1839 lua_pushboolean(L
, (*c
)->ismaxvert
);
1843 luaA_image_userdata_new(L
, (*c
)->icon
);
1848 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1849 lua_pushnumber(L
, d
);
1854 lua_pushboolean(L
, (*c
)->isontop
);
1857 lua_pushboolean(L
, (*c
)->isabove
);
1860 lua_pushboolean(L
, (*c
)->isbelow
);
1863 lua_pushboolean(L
, (*c
)->issticky
);
1865 case A_TK_HONORSIZEHINTS
:
1866 luaA_deprecate(L
, "size_hints_honor");
1867 case A_TK_SIZE_HINTS_HONOR
:
1868 lua_pushboolean(L
, (*c
)->size_hints_honor
);
1870 case A_TK_BORDER_WIDTH
:
1871 lua_pushnumber(L
, (*c
)->border
);
1873 case A_TK_BORDER_COLOR
:
1874 luaA_pushcolor(L
, &(*c
)->border_color
);
1878 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1881 lua_pushboolean(L
, (*c
)->isurgent
);
1883 case A_TK_SIZE_HINTS
:
1885 const char *u_or_p
= NULL
;
1889 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1890 u_or_p
= "user_position";
1891 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1892 u_or_p
= "program_position";
1897 lua_pushnumber(L
, (*c
)->size_hints
.x
);
1898 lua_setfield(L
, -2, "x");
1899 lua_pushnumber(L
, (*c
)->size_hints
.y
);
1900 lua_setfield(L
, -2, "y");
1901 lua_setfield(L
, -2, u_or_p
);
1905 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1906 u_or_p
= "user_size";
1907 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1908 u_or_p
= "program_size";
1913 lua_pushnumber(L
, (*c
)->size_hints
.width
);
1914 lua_setfield(L
, -2, "width");
1915 lua_pushnumber(L
, (*c
)->size_hints
.height
);
1916 lua_setfield(L
, -2, "height");
1917 lua_setfield(L
, -2, u_or_p
);
1920 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1922 lua_pushnumber(L
, (*c
)->size_hints
.min_width
);
1923 lua_setfield(L
, -2, "min_width");
1924 lua_pushnumber(L
, (*c
)->size_hints
.min_height
);
1925 lua_setfield(L
, -2, "min_height");
1928 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1930 lua_pushnumber(L
, (*c
)->size_hints
.max_width
);
1931 lua_setfield(L
, -2, "max_width");
1932 lua_pushnumber(L
, (*c
)->size_hints
.max_height
);
1933 lua_setfield(L
, -2, "max_height");
1936 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1938 lua_pushnumber(L
, (*c
)->size_hints
.width_inc
);
1939 lua_setfield(L
, -2, "width_inc");
1940 lua_pushnumber(L
, (*c
)->size_hints
.height_inc
);
1941 lua_setfield(L
, -2, "height_inc");
1944 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1946 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_num
);
1947 lua_setfield(L
, -2, "min_aspect_num");
1948 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_den
);
1949 lua_setfield(L
, -2, "min_aspect_den");
1950 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_num
);
1951 lua_setfield(L
, -2, "max_aspect_num");
1952 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_den
);
1953 lua_setfield(L
, -2, "max_aspect_den");
1956 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1958 lua_pushnumber(L
, (*c
)->size_hints
.base_width
);
1959 lua_setfield(L
, -2, "base_width");
1960 lua_pushnumber(L
, (*c
)->size_hints
.base_height
);
1961 lua_setfield(L
, -2, "base_height");
1964 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1966 switch((*c
)->size_hints
.win_gravity
)
1969 lua_pushliteral(L
, "north_west");
1971 case XCB_GRAVITY_NORTH
:
1972 lua_pushliteral(L
, "north");
1974 case XCB_GRAVITY_NORTH_EAST
:
1975 lua_pushliteral(L
, "north_east");
1977 case XCB_GRAVITY_WEST
:
1978 lua_pushliteral(L
, "west");
1980 case XCB_GRAVITY_CENTER
:
1981 lua_pushliteral(L
, "center");
1983 case XCB_GRAVITY_EAST
:
1984 lua_pushliteral(L
, "east");
1986 case XCB_GRAVITY_SOUTH_WEST
:
1987 lua_pushliteral(L
, "south_west");
1989 case XCB_GRAVITY_SOUTH
:
1990 lua_pushliteral(L
, "south");
1992 case XCB_GRAVITY_SOUTH_EAST
:
1993 lua_pushliteral(L
, "south_east");
1995 case XCB_GRAVITY_STATIC
:
1996 lua_pushliteral(L
, "static");
1999 lua_setfield(L
, -2, "win_gravity");
2010 /** Get or set mouse buttons bindings for a client.
2011 * \param L The Lua VM state.
2012 * \return The number of element pushed on stack.
2015 * \lparam An array of mouse button bindings objects, or nothing.
2016 * \return The array of mouse button bindings objects of this client.
2019 luaA_client_buttons(lua_State
*L
)
2021 client_t
**client
= luaA_checkudata(L
, 1, "client");
2022 button_array_t
*buttons
= &(*client
)->buttons
;
2024 if(lua_gettop(L
) == 2)
2025 luaA_button_array_set(L
, 2, buttons
);
2027 return luaA_button_array_get(L
, buttons
);
2030 /** Get or set keys bindings for a client.
2031 * \param L The Lua VM state.
2032 * \return The number of element pushed on stack.
2035 * \lparam An array of key bindings objects, or nothing.
2036 * \return The array of key bindings objects of this client.
2039 luaA_client_keys(lua_State
*L
)
2041 client_t
**c
= luaA_checkudata(L
, 1, "client");
2042 keybindings_t
*keys
= &(*c
)->keys
;
2044 if(lua_gettop(L
) == 2)
2046 luaA_key_array_set(L
, 2, keys
);
2047 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, (*c
)->win
, XCB_BUTTON_MASK_ANY
);
2048 window_grabkeys((*c
)->win
, keys
);
2051 return luaA_key_array_get(L
, keys
);
2054 /** Send fake events to a client.
2055 * \param L The Lua VM state.
2056 * \return The number of element pushed on stack.
2059 * \param The event type: key_press, key_release, button_press, button_release
2061 * \param The detail: in case of a key event, this is the keycode to send, in
2062 * case of a button event this is the number of the button. In case of a motion
2063 * event, this is a boolean value which if true make the coordinates relatives.
2064 * \param In case of a motion event, this is the X coordinate.
2065 * \param In case of a motion event, this is the Y coordinate.
2068 luaA_client_fake_input(lua_State
*L
)
2070 if(!globalconf
.have_xtest
)
2072 luaA_warn(L
, "XTest extension is not available, cannot fake input.");
2076 client_t
**c
= luaA_checkudata(L
, 1, "client");
2078 const char *stype
= luaL_checklstring(L
, 2, &tlen
);
2079 uint8_t type
, detail
;
2082 switch(a_tokenize(stype
, tlen
))
2084 case A_TK_KEY_PRESS
:
2085 type
= XCB_KEY_PRESS
;
2086 detail
= luaL_checknumber(L
, 3); /* keycode */
2088 case A_TK_KEY_RELEASE
:
2089 type
= XCB_KEY_RELEASE
;
2090 detail
= luaL_checknumber(L
, 3); /* keycode */
2092 case A_TK_BUTTON_PRESS
:
2093 type
= XCB_BUTTON_PRESS
;
2094 detail
= luaL_checknumber(L
, 3); /* button number */
2096 case A_TK_BUTTON_RELEASE
:
2097 type
= XCB_BUTTON_RELEASE
;
2098 detail
= luaL_checknumber(L
, 3); /* button number */
2100 case A_TK_MOTION_NOTIFY
:
2101 type
= XCB_MOTION_NOTIFY
;
2102 detail
= luaA_checkboolean(L
, 3); /* relative to the current position or not */
2103 x
= luaL_checknumber(L
, 4);
2104 y
= luaL_checknumber(L
, 5);
2110 xcb_test_fake_input(globalconf
.connection
,
2121 * \param L The Lua VM state.
2122 * \return The number of pushed elements.
2125 luaA_client_module_index(lua_State
*L
)
2128 const char *buf
= luaL_checklstring(L
, 2, &len
);
2130 switch(a_tokenize(buf
, len
))
2133 if(globalconf
.screen_focus
->client_focus
)
2134 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
2145 /* Client module new index.
2146 * \param L The Lua VM state.
2147 * \return The number of pushed elements.
2150 luaA_client_module_newindex(lua_State
*L
)
2153 const char *buf
= luaL_checklstring(L
, 2, &len
);
2156 switch(a_tokenize(buf
, len
))
2159 c
= luaA_checkudata(L
, 3, "client");
2169 /** Move a client with mouse (DEPRECATED).
2170 * \param L The Lua VM state.
2173 luaA_client_mouse_move(lua_State
*L
)
2175 luaA_deprecate(L
, "awful.mouse.client.move()");
2179 /** Resize a client with mouse (DEPRECATED).
2180 * \param L The Lua VM state.
2181 * \return The number of pushed elements.
2184 luaA_client_mouse_resize(lua_State
*L
)
2186 luaA_deprecate(L
, "awful.mouse.client.resize()");
2190 const struct luaL_reg awesome_client_methods
[] =
2192 { "get", luaA_client_get
},
2193 { "__index", luaA_client_module_index
},
2194 { "__newindex", luaA_client_module_newindex
},
2197 const struct luaL_reg awesome_client_meta
[] =
2199 { "isvisible", luaA_client_isvisible
},
2200 { "geometry", luaA_client_geometry
},
2201 { "struts", luaA_client_struts
},
2202 { "buttons", luaA_client_buttons
},
2203 { "keys", luaA_client_keys
},
2204 { "tags", luaA_client_tags
},
2205 { "kill", luaA_client_kill
},
2206 { "swap", luaA_client_swap
},
2207 { "raise", luaA_client_raise
},
2208 { "lower", luaA_client_lower
},
2209 { "redraw", luaA_client_redraw
},
2210 { "mouse_resize", luaA_client_mouse_resize
},
2211 { "mouse_move", luaA_client_mouse_move
},
2212 { "unmanage", luaA_client_unmanage
},
2213 { "fake_input", luaA_client_fake_input
},
2214 { "__index", luaA_client_index
},
2215 { "__newindex", luaA_client_newindex
},
2216 { "__eq", luaA_client_eq
},
2217 { "__gc", luaA_client_gc
},
2218 { "__tostring", luaA_client_tostring
},
2222 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80