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
++)
71 tag_client(c
, tags
->tab
[i
]);
73 untag_client(c
, tags
->tab
[i
]);
77 /* check for fullscreen */
78 reply
= xcb_get_property_reply(globalconf
.connection
, fullscreen_q
, NULL
);
80 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
81 client_setfullscreen(c
, *(bool *) data
);
87 /** Check if client supports protocol a protocole in WM_PROTOCOL.
88 * \param win The window.
89 * \return True if client has the atom in protocol, false otherwise.
92 window_hasproto(xcb_window_t win
, xcb_atom_t atom
)
95 xcb_get_wm_protocols_reply_t protocols
;
98 if(xcb_get_wm_protocols_reply(globalconf
.connection
,
99 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
103 for(i
= 0; !ret
&& i
< protocols
.atoms_len
; i
++)
104 if(protocols
.atoms
[i
] == atom
)
106 xcb_get_wm_protocols_reply_wipe(&protocols
);
111 /** Returns true if a client is tagged
112 * with one of the tags of the specified screen.
113 * \param c The client to check.
114 * \param screen Virtual screen number.
115 * \return true if the client is visible, false otherwise.
118 client_maybevisible(client_t
*c
, int screen
)
120 if(c
->screen
== screen
)
122 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
125 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
127 for(int i
= 0; i
< tags
->len
; i
++)
128 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
134 /** Return the content of a client as an image.
135 * That's just take a screenshot.
136 * \param c The client.
140 client_getcontent(client_t
*c
)
142 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
145 c
->geometries
.internal
.width
,
146 c
->geometries
.internal
.height
,
147 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
149 if(!ximage
|| ximage
->bpp
< 24)
152 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
154 for(int y
= 0; y
< ximage
->height
; y
++)
155 for(int x
= 0; x
< ximage
->width
; x
++)
157 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
158 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
161 image_t
*image
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
163 xcb_image_destroy(ximage
);
168 /** Get a client by its window.
169 * \param w The client window to find.
170 * \return A client pointer if found, NULL otherwise.
173 client_getbywin(xcb_window_t w
)
176 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
180 /** Unfocus a client.
181 * \param c The client.
184 client_unfocus(client_t
*c
)
186 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
187 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
189 /* Set focus on root window, so no events leak to the current window. */
190 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
191 root_win
, XCB_CURRENT_TIME
);
194 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
196 luaA_client_userdata_new(globalconf
.L
, c
);
197 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
200 ewmh_update_net_active_window(c
->phys_screen
);
203 /** Ban client and move it out of the viewport.
204 * \param c The client.
207 client_ban(client_t
*c
)
211 /* Move all clients out of the physical viewport into negative coordinate space. */
212 /* They will all be put on top of each other. */
213 uint32_t request
[2] = { - (c
->geometries
.internal
.width
+ 2 * c
->border
),
214 - (c
->geometries
.internal
.height
+ 2 * c
->border
) };
216 xcb_configure_window(globalconf
.connection
, c
->win
,
217 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
220 /* Do it manually because client geometry remains unchanged. */
223 simple_window_t
*sw
= &c
->titlebar
->sw
;
227 request
[0] = - (sw
->geometry
.width
);
228 request
[1] = - (sw
->geometry
.height
);
229 /* Move the titlebar to the same place as the window. */
230 xcb_configure_window(globalconf
.connection
, sw
->window
,
231 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
238 /* All the wiboxes (may) need to be repositioned. */
239 if(client_hasstrut(c
))
240 wibox_update_positions();
243 /* Wait until the last moment to take away the focus from the window. */
244 if (globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
248 /** Give focus to client, or to first client if client is NULL.
249 * \param c The client or NULL.
250 * \return True if a window (even root) has received focus, false otherwise.
253 client_focus(client_t
*c
)
255 if(!client_maybevisible(c
, c
->screen
) || c
->nofocus
)
258 /* unfocus current selected client */
259 if(globalconf
.screen_focus
->client_focus
260 && c
!= globalconf
.screen_focus
->client_focus
)
261 client_unfocus(globalconf
.screen_focus
->client_focus
);
265 client_setminimized(c
, false);
267 /* unban the client before focusing or it will fail */
270 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
271 globalconf
.screen_focus
->client_focus
= c
;
273 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
274 c
->win
, XCB_CURRENT_TIME
);
276 /* Some layouts use focused client differently, so call them back.
277 * And anyway, we have maybe unhidden */
278 client_need_arrange(c
);
281 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
283 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
284 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
287 ewmh_update_net_active_window(c
->phys_screen
);
290 /** Stack a window below.
291 * \param c The client.
292 * \param previous The previous window on the stack.
293 * \param return The next-previous!
296 client_stack_above(client_t
*c
, xcb_window_t previous
)
298 uint32_t config_win_vals
[2];
300 config_win_vals
[0] = previous
;
301 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
303 xcb_configure_window(globalconf
.connection
, c
->win
,
304 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
307 config_win_vals
[0] = c
->win
;
311 xcb_configure_window(globalconf
.connection
,
312 c
->titlebar
->sw
.window
,
313 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
315 previous
= c
->titlebar
->sw
.window
;
320 /* stack transient window on top of their parents */
321 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
322 node
; node
= node
->prev
)
323 if(node
->client
->transient_for
== c
)
325 client_stack_above(node
->client
,
327 previous
= node
->client
->win
;
333 /** Stacking layout layers */
336 /** This one is a special layer */
347 /** Get the real layer of a client according to its attribute (fullscreen, …)
348 * \param c The client.
349 * \return The real layer.
352 client_layer_translator(client_t
*c
)
354 /* first deal with user set attributes */
357 else if(c
->isfullscreen
)
358 return LAYER_FULLSCREEN
;
364 /* check for transient attr */
368 /* then deal with windows type */
371 case WINDOW_TYPE_DOCK
:
373 case WINDOW_TYPE_DESKTOP
:
374 return LAYER_DESKTOP
;
375 case WINDOW_TYPE_DIALOG
:
376 case WINDOW_TYPE_MENU
:
377 case WINDOW_TYPE_TOOLBAR
:
378 case WINDOW_TYPE_UTILITY
:
388 * \todo It might be worth stopping to restack everyone and only stack `c'
389 * relatively to the first matching in the list.
394 uint32_t config_win_vals
[2];
395 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
399 config_win_vals
[0] = XCB_NONE
;
400 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
402 /* stack desktop windows */
403 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
404 for(node
= last
; node
; node
= node
->prev
)
405 if(client_layer_translator(node
->client
) == layer
)
406 config_win_vals
[0] = client_stack_above(node
->client
,
409 /* first stack not ontop wibox window */
410 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
411 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
413 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
416 xcb_configure_window(globalconf
.connection
,
418 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
420 config_win_vals
[0] = sb
->sw
.window
;
424 /* stack bottom layers */
425 for(layer
= LAYER_BELOW
; layer
< LAYER_FULLSCREEN
; layer
++)
426 for(node
= last
; node
; node
= node
->prev
)
427 if(client_layer_translator(node
->client
) == layer
)
428 config_win_vals
[0] = client_stack_above(node
->client
,
431 /* then stack ontop wibox window */
432 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
433 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
435 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
438 xcb_configure_window(globalconf
.connection
,
440 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
442 config_win_vals
[0] = sb
->sw
.window
;
446 /* finally stack ontop and fullscreen windows */
447 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
448 for(node
= last
; node
; node
= node
->prev
)
449 if(client_layer_translator(node
->client
) == layer
)
450 config_win_vals
[0] = client_stack_above(node
->client
,
454 /** Copy tags from one client to another client on the same screen.
455 * Be careful: this does not untag!
456 * \param src_c The source client.
457 * \param dst_c The destination client.
460 client_duplicate_tags(client_t
*src_c
, client_t
*dst_c
)
463 tag_array_t
*tags
= &globalconf
.screens
[src_c
->screen
].tags
;
465 /* Avoid doing dangerous things. */
466 if (src_c
->screen
!= dst_c
->screen
)
469 for(i
= 0; i
< tags
->len
; i
++)
470 if(is_client_tagged(src_c
, tags
->tab
[i
]))
471 tag_client(dst_c
, tags
->tab
[i
]);
474 /** Manage a new client.
475 * \param w The window.
476 * \param wgeom Window geometry.
477 * \param phys_screen Physical screen number.
478 * \param startup True if we are managing at startup time.
481 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
483 xcb_get_property_cookie_t ewmh_icon_cookie
;
484 client_t
*c
, *tc
= NULL
, *group
= NULL
;
487 const uint32_t select_input_val
[] =
489 XCB_EVENT_MASK_STRUCTURE_NOTIFY
490 | XCB_EVENT_MASK_PROPERTY_CHANGE
491 | XCB_EVENT_MASK_ENTER_WINDOW
492 | XCB_EVENT_MASK_LEAVE_WINDOW
496 if(systray_iskdedockapp(w
))
498 systray_request_handle(w
, phys_screen
, NULL
);
502 /* Send request to get NET_WM_ICON property as soon as possible... */
503 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
504 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
505 c
= p_new(client_t
, 1);
507 screen
= c
->screen
= screen_getbycoord(phys_screen
, wgeom
->x
, wgeom
->y
);
509 c
->phys_screen
= phys_screen
;
513 c
->geometry
.x
= wgeom
->x
;
514 c
->geometry
.y
= wgeom
->y
;
515 c
->geometry
.width
= wgeom
->width
+ 2 * wgeom
->border_width
;
516 c
->geometry
.height
= wgeom
->height
+ 2 * wgeom
->border_width
;
517 /* Also set internal geometry (client_ban() needs it). */
518 c
->geometries
.internal
.x
= wgeom
->x
;
519 c
->geometries
.internal
.y
= wgeom
->y
;
520 c
->geometries
.internal
.width
= wgeom
->width
;
521 c
->geometries
.internal
.height
= wgeom
->height
;
522 client_setborder(c
, wgeom
->border_width
);
523 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
524 c
->icon
= image_ref(&icon
);
526 /* we honor size hints by default */
527 c
->size_hints_honor
= true;
530 property_update_wm_normal_hints(c
, NULL
);
531 property_update_wm_hints(c
, NULL
);
532 property_update_wm_transient_for(c
, NULL
);
533 property_update_wm_client_leader(c
, NULL
);
535 /* Recursively find the parent. */
536 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
540 /* Try to load props, if it fails check for group windows.
541 * transient_for windows are excluded, because they inherit the parent tags. */
542 if(!client_loadprops(c
, &globalconf
.screens
[screen
])
544 && !c
->transient_for
)
545 /* Try to find a group of windows for better initial placement. */
546 for(group
= globalconf
.clients
; group
; group
= group
->next
)
547 if(group
->group_win
== c
->group_win
)
550 /* Move to the right screen.
551 * Assumption: Window groups do not span multiple logical screens. */
553 screen
= group
->screen
;
555 /* Then check clients hints */
556 ewmh_client_check_hints(c
);
558 /* move client to screen, but do not tag it for now */
559 screen_client_moveto(c
, screen
, false, true);
561 /* Duplicate the tags of either the parent or a group window.
562 * Otherwise check for existing tags, if that fails tag it with the current tag.
563 * This could be done lua side, but it's sane behaviour. */
567 client_duplicate_tags(tc
, c
);
569 client_duplicate_tags(group
, c
);
573 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
574 for(i
= 0; i
< tags
->len
; i
++)
575 if(is_client_tagged(c
, tags
->tab
[i
]))
578 /* if no tag, set current selected */
580 for(i
= 0; i
< tags
->len
; i
++)
581 if(tags
->tab
[i
]->selected
)
582 tag_client(c
, tags
->tab
[i
]);
586 /* Push client in client list */
587 client_list_push(&globalconf
.clients
, client_ref(&c
));
589 /* Push client in stack */
592 /* update window title */
593 property_update_wm_name(c
);
594 property_update_wm_icon_name(c
);
597 ewmh_client_strut_update(c
, NULL
);
599 ewmh_update_net_client_list(c
->phys_screen
);
601 /* Always stay in NORMAL_STATE. Even though iconified seems more
602 * appropriate sometimes. The only possible loss is that clients not using
603 * visibility events may continue to proces data (when banned).
604 * Without any exposes or other events the cost should be fairly limited though.
606 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
607 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
609 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
610 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
612 * "Once a client's window has left the Withdrawn state, the window will be mapped
613 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
615 * At this stage it's just safer to keep it in normal state and avoid confusion.
617 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
619 /* Move window outside the viewport before mapping it. */
621 xcb_map_window(globalconf
.connection
, c
->win
);
623 /* Call hook to notify list change */
624 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
625 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
628 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
630 luaA_client_userdata_new(globalconf
.L
, c
);
631 lua_pushboolean(globalconf
.L
, startup
);
632 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
636 /** Compute client geometry with respect to its geometry hints.
637 * \param c The client.
638 * \param geometry The geometry that the client might receive.
639 * \return The geometry the client must take respecting its hints.
642 client_geometry_hints(client_t
*c
, area_t geometry
)
644 int32_t basew
, baseh
, minw
, minh
;
646 /* base size is substituted with min size if not specified */
647 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
649 basew
= c
->size_hints
.base_width
;
650 baseh
= c
->size_hints
.base_height
;
652 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
654 basew
= c
->size_hints
.min_width
;
655 baseh
= c
->size_hints
.min_height
;
660 /* min size is substituted with base size if not specified */
661 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
663 minw
= c
->size_hints
.min_width
;
664 minh
= c
->size_hints
.min_height
;
666 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
668 minw
= c
->size_hints
.base_width
;
669 minh
= c
->size_hints
.base_height
;
674 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
675 && c
->size_hints
.min_aspect_num
> 0
676 && c
->size_hints
.min_aspect_den
> 0
677 && geometry
.height
- baseh
> 0
678 && geometry
.width
- basew
> 0)
680 double dx
= (double) (geometry
.width
- basew
);
681 double dy
= (double) (geometry
.height
- baseh
);
682 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
683 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
684 double ratio
= dx
/ dy
;
685 if(max
> 0 && min
> 0 && ratio
> 0)
689 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
691 geometry
.width
= (int) dx
+ basew
;
692 geometry
.height
= (int) dy
+ baseh
;
696 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
698 geometry
.width
= (int) dx
+ basew
;
699 geometry
.height
= (int) dy
+ baseh
;
705 geometry
.width
= MAX(geometry
.width
, minw
);
707 geometry
.height
= MAX(geometry
.height
, minh
);
709 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
711 if(c
->size_hints
.max_width
)
712 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
713 if(c
->size_hints
.max_height
)
714 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
717 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
718 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
720 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
721 unsigned_subtract(t1
, basew
);
722 unsigned_subtract(t2
, baseh
);
723 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
724 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
730 /** Resize client window.
731 * \param c Client to resize.
732 * \param geometry New window geometry.
733 * \param hints Use size hints.
736 client_resize(client_t
*c
, area_t geometry
, bool hints
)
739 area_t geometry_internal
;
742 /* offscreen appearance fixes */
743 area
= display_area_get(c
->phys_screen
, NULL
,
744 &globalconf
.screens
[c
->screen
].padding
);
746 if(geometry
.x
> area
.width
)
747 geometry
.x
= area
.width
- geometry
.width
;
748 if(geometry
.y
> area
.height
)
749 geometry
.y
= area
.height
- geometry
.height
;
750 if(geometry
.x
+ geometry
.width
< 0)
752 if(geometry
.y
+ geometry
.height
< 0)
755 /* Real client geometry, please keep it contained to C code at the very least. */
756 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
759 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
761 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
764 /* Also let client hints propegate to the "official" geometry. */
765 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
767 if(c
->geometries
.internal
.x
!= geometry_internal
.x
768 || c
->geometries
.internal
.y
!= geometry_internal
.y
769 || c
->geometries
.internal
.width
!= geometry_internal
.width
770 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
772 new_screen
= screen_getbycoord(c
->screen
, geometry_internal
.x
, geometry_internal
.y
);
774 /* Values to configure a window is an array where values are
775 * stored according to 'value_mask' */
778 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
779 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
780 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
781 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
783 /* Also store geometry including border and titlebar. */
784 c
->geometry
= geometry
;
786 titlebar_update_geometry(c
);
788 /* The idea is to give a client a resize even when banned. */
789 /* We just have to move the (x,y) to keep it out of the viewport. */
790 /* This at least doesn't break expectations about events. */
793 geometry
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
794 geometry
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
797 xcb_configure_window(globalconf
.connection
, c
->win
,
798 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
799 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
801 window_configure(c
->win
, geometry_internal
, c
->border
);
803 screen_client_moveto(c
, new_screen
, true, false);
806 hooks_property(c
, "geometry");
810 /** Set a client minimized, or not.
811 * \param c The client.
812 * \param s Set or not the client minimized.
815 client_setminimized(client_t
*c
, bool s
)
817 if(c
->isminimized
!= s
)
819 client_need_arrange(c
);
821 client_need_arrange(c
);
822 ewmh_client_update_hints(c
);
824 hooks_property(c
, "minimized");
828 /** Set a client sticky, or not.
829 * \param c The client.
830 * \param s Set or not the client sticky.
833 client_setsticky(client_t
*c
, bool s
)
837 client_need_arrange(c
);
839 client_need_arrange(c
);
840 ewmh_client_update_hints(c
);
841 hooks_property(c
, "sticky");
845 /** Set a client fullscreen, or not.
846 * \param c The client.
847 * \param s Set or not the client fullscreen.
850 client_setfullscreen(client_t
*c
, bool s
)
852 if(c
->isfullscreen
!= s
)
856 /* become fullscreen! */
857 if((c
->isfullscreen
= s
))
859 /* remove any max state */
860 client_setmaxhoriz(c
, false);
861 client_setmaxvert(c
, false);
863 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
864 c
->geometries
.fullscreen
= c
->geometry
;
865 c
->border_fs
= c
->border
;
866 client_setborder(c
, 0);
870 geometry
= c
->geometries
.fullscreen
;
871 client_setborder(c
, c
->border_fs
);
873 client_resize(c
, geometry
, false);
874 client_need_arrange(c
);
876 xcb_change_property(globalconf
.connection
,
877 XCB_PROP_MODE_REPLACE
,
878 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
880 ewmh_client_update_hints(c
);
881 hooks_property(c
, "fullscreen");
885 /** Set a client horizontally maximized.
886 * \param c The client.
887 * \param s The maximized status.
890 client_setmaxhoriz(client_t
*c
, bool s
)
892 if(c
->ismaxhoriz
!= s
)
896 if((c
->ismaxhoriz
= s
))
898 /* remove fullscreen mode */
899 client_setfullscreen(c
, false);
901 geometry
= screen_area_get(c
->screen
,
902 &globalconf
.screens
[c
->screen
].wiboxes
,
903 &globalconf
.screens
[c
->screen
].padding
,
905 geometry
.y
= c
->geometry
.y
;
906 geometry
.height
= c
->geometry
.height
;
907 c
->geometries
.max
.x
= c
->geometry
.x
;
908 c
->geometries
.max
.width
= c
->geometry
.width
;
912 geometry
= c
->geometry
;
913 geometry
.x
= c
->geometries
.max
.x
;
914 geometry
.width
= c
->geometries
.max
.width
;
917 client_resize(c
, geometry
, c
->size_hints_honor
);
918 client_need_arrange(c
);
920 ewmh_client_update_hints(c
);
921 hooks_property(c
, "maximized_horizontal");
925 /** Set a client vertically maximized.
926 * \param c The client.
927 * \param s The maximized status.
930 client_setmaxvert(client_t
*c
, bool s
)
932 if(c
->ismaxvert
!= s
)
936 if((c
->ismaxvert
= s
))
938 /* remove fullscreen mode */
939 client_setfullscreen(c
, false);
941 geometry
= screen_area_get(c
->screen
,
942 &globalconf
.screens
[c
->screen
].wiboxes
,
943 &globalconf
.screens
[c
->screen
].padding
,
945 geometry
.x
= c
->geometry
.x
;
946 geometry
.width
= c
->geometry
.width
;
947 c
->geometries
.max
.y
= c
->geometry
.y
;
948 c
->geometries
.max
.height
= c
->geometry
.height
;
952 geometry
= c
->geometry
;
953 geometry
.y
= c
->geometries
.max
.y
;
954 geometry
.height
= c
->geometries
.max
.height
;
957 client_resize(c
, geometry
, c
->size_hints_honor
);
958 client_need_arrange(c
);
960 ewmh_client_update_hints(c
);
961 hooks_property(c
, "maximized_vertical");
965 /** Set a client above, or not.
966 * \param c The client.
967 * \param s Set or not the client above.
970 client_setabove(client_t
*c
, bool s
)
976 ewmh_client_update_hints(c
);
978 hooks_property(c
, "above");
982 /** Set a client below, or not.
983 * \param c The client.
984 * \param s Set or not the client below.
987 client_setbelow(client_t
*c
, bool s
)
993 ewmh_client_update_hints(c
);
995 hooks_property(c
, "below");
999 /** Set a client modal, or not.
1000 * \param c The client.
1001 * \param s Set or not the client moda.
1004 client_setmodal(client_t
*c
, bool s
)
1010 ewmh_client_update_hints(c
);
1012 hooks_property(c
, "modal");
1016 /** Set a client ontop, or not.
1017 * \param c The client.
1018 * \param s Set or not the client moda.
1021 client_setontop(client_t
*c
, bool s
)
1028 hooks_property(c
, "ontop");
1032 /** Save client properties as an X property.
1033 * \param c The client.
1036 client_saveprops_tags(client_t
*c
)
1038 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1039 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
1042 for(i
= 0; i
< tags
->len
; i
++)
1043 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
1045 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
1048 /** Unban a client and move it back into the viewport.
1049 * \param c The client.
1052 client_unban(client_t
*c
)
1056 /* Move the client back where it belongs. */
1057 uint32_t request
[2] = { c
->geometries
.internal
.x
, c
->geometries
.internal
.y
};
1059 xcb_configure_window(globalconf
.connection
, c
->win
,
1060 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
1062 window_configure(c
->win
, c
->geometries
.internal
, c
->border
);
1064 /* Do this manually because the system doesn't know we moved the toolbar.
1065 * Note that !isvisible titlebars are unmapped and for fullscreen it'll
1066 * end up offscreen anyway. */
1069 simple_window_t
*sw
= &c
->titlebar
->sw
;
1070 /* All resizing is done, so only move now. */
1071 request
[0] = sw
->geometry
.x
;
1072 request
[1] = sw
->geometry
.y
;
1074 xcb_configure_window(globalconf
.connection
, sw
->window
,
1075 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
1079 c
->isbanned
= false;
1081 /* All the wiboxes (may) need to be repositioned. */
1082 if(client_hasstrut(c
))
1083 wibox_update_positions();
1087 /** Unmanage a client.
1088 * \param c The client.
1091 client_unmanage(client_t
*c
)
1093 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
1095 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
1098 /* remove client everywhere */
1099 client_list_detach(&globalconf
.clients
, c
);
1100 stack_client_delete(c
);
1101 for(int i
= 0; i
< tags
->len
; i
++)
1102 untag_client(c
, tags
->tab
[i
]);
1105 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1107 luaA_client_userdata_new(globalconf
.L
, c
);
1108 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1111 /* Call hook to notify list change */
1112 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1113 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1115 /* The server grab construct avoids race conditions. */
1116 xcb_grab_server(globalconf
.connection
);
1118 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1119 XCB_BUTTON_MASK_ANY
);
1120 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1122 xcb_flush(globalconf
.connection
);
1123 xcb_ungrab_server(globalconf
.connection
);
1125 titlebar_client_detach(c
);
1127 ewmh_update_net_client_list(c
->phys_screen
);
1129 /* delete properties */
1130 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
1131 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
1133 /* All the wiboxes (may) need to be repositioned. */
1134 if(client_hasstrut(c
))
1135 wibox_update_positions();
1137 /* set client as invalid */
1143 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1145 * \param c The client to kill.
1148 client_kill(client_t
*c
)
1150 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1152 xcb_client_message_event_t ev
;
1154 /* Initialize all of event's fields first */
1157 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1160 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1161 ev
.type
= WM_PROTOCOLS
;
1162 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1164 xcb_send_event(globalconf
.connection
, false, c
->win
,
1165 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1168 xcb_kill_client(globalconf
.connection
, c
->win
);
1171 /** Get all clients into a table.
1172 * \param L The Lua VM state.
1173 * \return The number of elements pushed on stack.
1175 * \lparam An optional screen nunmber.
1176 * \lreturn A table with all clients.
1179 luaA_client_get(lua_State
*L
)
1184 screen
= luaL_optnumber(L
, 1, 0) - 1;
1188 if(screen
== SCREEN_UNDEF
)
1189 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1191 luaA_client_userdata_new(globalconf
.L
, c
);
1192 lua_rawseti(L
, -2, i
++);
1196 luaA_checkscreen(screen
);
1197 for(c
= globalconf
.clients
; c
; c
= c
->next
)
1198 if(c
->screen
== screen
)
1200 luaA_client_userdata_new(globalconf
.L
, c
);
1201 lua_rawseti(L
, -2, i
++);
1208 /** Check if a client is visible on its screen.
1209 * \param L The Lua VM state.
1210 * \return The number of elements pushed on stack.
1213 * \lreturn A boolean value, true if the client is visible, false otherwise.
1216 luaA_client_isvisible(lua_State
*L
)
1218 client_t
**c
= luaA_checkudata(L
, 1, "client");
1219 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
1223 /** Set client border width.
1224 * \param c The client.
1225 * \param width The border width.
1228 client_setborder(client_t
*c
, int width
)
1232 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1233 || c
->type
== WINDOW_TYPE_SPLASH
1234 || c
->type
== WINDOW_TYPE_DESKTOP
1235 || c
->isfullscreen
))
1238 if(width
== c
->border
|| width
< 0)
1242 xcb_configure_window(globalconf
.connection
, c
->win
,
1243 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1245 client_need_arrange(c
);
1247 hooks_property(c
, "border_width");
1251 * \param L The Lua VM state.
1257 luaA_client_kill(lua_State
*L
)
1259 client_t
**c
= luaA_checkudata(L
, 1, "client");
1264 /** Swap a client with another one.
1265 * \param L The Lua VM state.
1268 * \lparam A client to swap with.
1271 luaA_client_swap(lua_State
*L
)
1273 client_t
**c
= luaA_checkudata(L
, 1, "client");
1274 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1278 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1279 client_need_arrange(*c
);
1280 client_need_arrange(*swap
);
1282 /* Call hook to notify list change */
1283 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1284 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1290 /** Access or set the client tags.
1291 * \param L The Lua VM state.
1292 * \return The number of elements pushed on stack.
1293 * \lparam A table with tags to set, or none to get the current tags table.
1294 * \return The clients tag.
1297 luaA_client_tags(lua_State
*L
)
1301 client_t
**c
= luaA_checkudata(L
, 1, "client");
1304 if(lua_gettop(L
) == 2)
1306 luaA_checktable(L
, 2);
1307 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1308 for(int i
= 0; i
< tags
->len
; i
++)
1309 untag_client(*c
, tags
->tab
[i
]);
1311 while(lua_next(L
, 2))
1313 tag
= luaA_checkudata(L
, -1, "tag");
1314 tag_client(*c
, *tag
);
1320 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1322 for(int i
= 0; i
< tags
->len
; i
++)
1323 if(is_client_tagged(*c
, tags
->tab
[i
]))
1325 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1326 lua_rawseti(L
, -2, ++j
);
1332 /** Raise a client on top of others which are on the same layer.
1333 * \param L The Lua VM state.
1338 luaA_client_raise(lua_State
*L
)
1340 client_t
**c
= luaA_checkudata(L
, 1, "client");
1345 /** Lower a client on bottom of others which are on the same layer.
1346 * \param L The Lua VM state.
1351 luaA_client_lower(lua_State
*L
)
1353 client_t
**c
= luaA_checkudata(L
, 1, "client");
1358 /** Redraw a client by unmapping and mapping it quickly.
1359 * \param L The Lua VM state.
1365 luaA_client_redraw(lua_State
*L
)
1367 client_t
**c
= luaA_checkudata(L
, 1, "client");
1369 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1370 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1372 /* Set the focus on the current window if the redraw has been
1373 performed on the window where the pointer is currently on
1374 because after the unmapping/mapping, the focus is lost */
1375 if(globalconf
.screen_focus
->client_focus
== *c
)
1376 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1377 (*c
)->win
, XCB_CURRENT_TIME
);
1382 /** Stop managing a client.
1383 * \param L The Lua VM state.
1384 * \return The number of elements pushed on stack.
1389 luaA_client_unmanage(lua_State
*L
)
1391 client_t
**c
= luaA_checkudata(L
, 1, "client");
1392 client_unmanage(*c
);
1396 /** Return client geometry.
1397 * \param L The Lua VM state.
1398 * \return The number of elements pushed on stack.
1400 * \lparam A table with new coordinates, or none.
1401 * \lreturn A table with client coordinates.
1404 luaA_client_geometry(lua_State
*L
)
1406 client_t
**c
= luaA_checkudata(L
, 1, "client");
1408 if(lua_gettop(L
) == 2)
1412 luaA_checktable(L
, 2);
1413 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1414 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1415 if(client_isfixed(*c
))
1417 geometry
.width
= (*c
)->geometry
.width
;
1418 geometry
.height
= (*c
)->geometry
.height
;
1422 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1423 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1426 client_resize(*c
, geometry
, (*c
)->size_hints_honor
);
1429 return luaA_pusharea(L
, (*c
)->geometry
);
1432 /** Client newindex.
1433 * \param L The Lua VM state.
1434 * \return The number of elements pushed on stack.
1437 luaA_client_newindex(lua_State
*L
)
1440 client_t
**c
= luaA_checkudata(L
, 1, "client");
1441 const char *buf
= luaL_checklstring(L
, 2, &len
);
1449 luaL_error(L
, "client is invalid\n");
1451 switch(a_tokenize(buf
, len
))
1454 if(globalconf
.xinerama_is_active
)
1456 i
= luaL_checknumber(L
, 3) - 1;
1457 luaA_checkscreen(i
);
1458 screen_client_moveto(*c
, i
, true, true);
1462 b
= luaA_checkboolean(L
, 3);
1463 if(b
!= (*c
)->ishidden
)
1465 client_need_arrange(*c
);
1467 client_need_arrange(*c
);
1471 luaA_deprecate(L
, "client.minimized");
1472 case A_TK_MINIMIZED
:
1473 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1475 case A_TK_FULLSCREEN
:
1476 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1478 case A_TK_MAXIMIZED_HORIZONTAL
:
1479 client_setmaxhoriz(*c
, luaA_checkboolean(L
, 3));
1481 case A_TK_MAXIMIZED_VERTICAL
:
1482 client_setmaxvert(*c
, luaA_checkboolean(L
, 3));
1485 image
= luaA_checkudata(L
, 3, "image");
1486 image_unref(&(*c
)->icon
);
1488 (*c
)->icon
= *image
;
1490 hooks_property(*c
, "icon");
1494 window_opacity_set((*c
)->win
, -1);
1497 d
= luaL_checknumber(L
, 3);
1498 if(d
>= 0 && d
<= 1)
1499 window_opacity_set((*c
)->win
, d
);
1503 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1505 case A_TK_HONORSIZEHINTS
:
1506 (*c
)->size_hints_honor
= luaA_checkboolean(L
, 3);
1507 client_need_arrange(*c
);
1509 case A_TK_BORDER_WIDTH
:
1510 client_setborder(*c
, luaL_checknumber(L
, 3));
1513 client_setontop(*c
, luaA_checkboolean(L
, 3));
1515 case A_TK_BORDER_COLOR
:
1516 if((buf
= luaL_checklstring(L
, 3, &len
))
1517 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1518 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1519 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1523 titlebar_client_detach(*c
);
1526 t
= luaA_checkudata(L
, 3, "wibox");
1527 titlebar_client_attach(*c
, *t
);
1538 * \param L The Lua VM state.
1539 * \return The number of elements pushed on stack.
1541 * \lfield name The client title.
1542 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1543 * \lfield type The window type (desktop, normal, dock, …).
1544 * \lfield class The client class.
1545 * \lfield instance The client instance.
1546 * \lfield pid The client PID, if available.
1547 * \lfield role The window role, if available.
1548 * \lfield machine The machine client is running on.
1549 * \lfield icon_name The client name when iconified.
1550 * \lfield screen Client screen number.
1551 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1552 * invisible in taskbar.
1553 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1555 * \lfield icon_path Path to the icon used to identify.
1556 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1557 * \lfield border_width The client border width.
1558 * \lfield border_color The client border color.
1559 * \lfield titlebar The client titlebar.
1560 * \lfield urgent The client urgent state.
1561 * \lfield content An image representing the client window content (screenshot).
1562 * \lfield focus The focused client.
1563 * \lfield opacity The client opacity between 0 and 1.
1564 * \lfield ontop The client is on top of every other windows.
1565 * \lfield fullscreen The client is fullscreen or not.
1566 * \lfield maximized_horizontal The client is maximized horizontally or not.
1567 * \lfield maximized_vertical The client is maximized vertically or not.
1568 * \lfield transient_for Return the client the window is transient for.
1569 * \lfield group_id Identification unique to a group of windows.
1570 * \lfield leader_id Identification unique to windows spawned by the same command.
1571 * \lfield size_hints A table with size hints of the client: user_position,
1572 * user_size, program_position, program_size, etc.
1575 luaA_client_index(lua_State
*L
)
1579 client_t
**c
= luaA_checkudata(L
, 1, "client");
1580 const char *buf
= luaL_checklstring(L
, 2, &len
);
1583 xcb_get_wm_class_reply_t hint
;
1584 xcb_get_property_cookie_t prop_c
;
1585 xcb_get_property_reply_t
*prop_r
= NULL
;
1589 luaL_error(L
, "client is invalid\n");
1591 if(luaA_usemetatable(L
, 1, 2))
1594 switch(a_tokenize(buf
, len
))
1599 lua_pushstring(L
, (*c
)->name
);
1601 case A_TK_TRANSIENT_FOR
:
1602 if((*c
)->transient_for
)
1603 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1605 case A_TK_SKIP_TASKBAR
:
1606 lua_pushboolean(L
, (*c
)->skiptb
);
1609 if((image
= client_getcontent(*c
)))
1610 return luaA_image_userdata_new(L
, image
);
1615 case WINDOW_TYPE_DESKTOP
:
1616 lua_pushliteral(L
, "desktop");
1618 case WINDOW_TYPE_DOCK
:
1619 lua_pushliteral(L
, "dock");
1621 case WINDOW_TYPE_SPLASH
:
1622 lua_pushliteral(L
, "splash");
1624 case WINDOW_TYPE_DIALOG
:
1625 lua_pushliteral(L
, "dialog");
1627 case WINDOW_TYPE_MENU
:
1628 lua_pushliteral(L
, "menu");
1630 case WINDOW_TYPE_TOOLBAR
:
1631 lua_pushliteral(L
, "toolbar");
1633 case WINDOW_TYPE_UTILITY
:
1634 lua_pushliteral(L
, "utility");
1637 lua_pushliteral(L
, "normal");
1642 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1643 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1646 lua_pushstring(L
, hint
.class);
1647 xcb_get_wm_class_reply_wipe(&hint
);
1650 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1651 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1654 lua_pushstring(L
, hint
.name
);
1655 xcb_get_wm_class_reply_wipe(&hint
);
1658 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1659 WM_WINDOW_ROLE
, &value
, &slen
))
1661 lua_pushlstring(L
, value
, slen
);
1665 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1666 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1668 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1669 lua_pushnumber(L
, *(uint32_t *)data
);
1676 case A_TK_LEADER_ID
:
1677 lua_pushnumber(L
, (*c
)->leader_win
);
1680 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1681 WM_CLIENT_MACHINE
, &value
, &slen
))
1683 lua_pushlstring(L
, value
, slen
);
1686 case A_TK_ICON_NAME
:
1687 lua_pushstring(L
, (*c
)->icon_name
);
1690 lua_pushnumber(L
, 1 + (*c
)->screen
);
1693 lua_pushboolean(L
, (*c
)->ishidden
);
1696 luaA_deprecate(L
, "client.minimized");
1697 case A_TK_MINIMIZED
:
1698 lua_pushboolean(L
, (*c
)->isminimized
);
1700 case A_TK_FULLSCREEN
:
1701 lua_pushboolean(L
, (*c
)->isfullscreen
);
1705 lua_pushnumber(L
, (*c
)->group_win
);
1709 case A_TK_MAXIMIZED_HORIZONTAL
:
1710 lua_pushboolean(L
, (*c
)->ismaxhoriz
);
1712 case A_TK_MAXIMIZED_VERTICAL
:
1713 lua_pushboolean(L
, (*c
)->ismaxvert
);
1717 luaA_image_userdata_new(L
, (*c
)->icon
);
1722 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1723 lua_pushnumber(L
, d
);
1728 lua_pushboolean(L
, (*c
)->isontop
);
1731 lua_pushboolean(L
, (*c
)->issticky
);
1733 case A_TK_HONORSIZEHINTS
:
1734 luaA_deprecate(L
, "size_hints_honor");
1735 case A_TK_SIZE_HINTS_HONOR
:
1736 lua_pushboolean(L
, (*c
)->size_hints_honor
);
1738 case A_TK_BORDER_WIDTH
:
1739 lua_pushnumber(L
, (*c
)->border
);
1741 case A_TK_BORDER_COLOR
:
1742 luaA_pushcolor(L
, &(*c
)->border_color
);
1746 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1749 lua_pushboolean(L
, (*c
)->isurgent
);
1751 case A_TK_SIZE_HINTS
:
1753 const char *u_or_p
= NULL
;
1757 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1758 u_or_p
= "user_position";
1759 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1760 u_or_p
= "program_position";
1765 lua_pushnumber(L
, (*c
)->size_hints
.x
);
1766 lua_setfield(L
, -2, "x");
1767 lua_pushnumber(L
, (*c
)->size_hints
.y
);
1768 lua_setfield(L
, -2, "y");
1769 lua_setfield(L
, -2, u_or_p
);
1773 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1774 u_or_p
= "user_size";
1775 else if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1776 u_or_p
= "program_size";
1781 lua_pushnumber(L
, (*c
)->size_hints
.width
);
1782 lua_setfield(L
, -2, "width");
1783 lua_pushnumber(L
, (*c
)->size_hints
.height
);
1784 lua_setfield(L
, -2, "height");
1785 lua_setfield(L
, -2, u_or_p
);
1788 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1790 lua_pushnumber(L
, (*c
)->size_hints
.min_width
);
1791 lua_setfield(L
, -2, "min_width");
1792 lua_pushnumber(L
, (*c
)->size_hints
.min_height
);
1793 lua_setfield(L
, -2, "min_height");
1796 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1798 lua_pushnumber(L
, (*c
)->size_hints
.max_width
);
1799 lua_setfield(L
, -2, "max_width");
1800 lua_pushnumber(L
, (*c
)->size_hints
.max_height
);
1801 lua_setfield(L
, -2, "max_height");
1804 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1806 lua_pushnumber(L
, (*c
)->size_hints
.width_inc
);
1807 lua_setfield(L
, -2, "width_inc");
1808 lua_pushnumber(L
, (*c
)->size_hints
.height_inc
);
1809 lua_setfield(L
, -2, "height_inc");
1812 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1814 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_num
);
1815 lua_setfield(L
, -2, "min_aspect_num");
1816 lua_pushnumber(L
, (*c
)->size_hints
.min_aspect_den
);
1817 lua_setfield(L
, -2, "min_aspect_den");
1818 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_num
);
1819 lua_setfield(L
, -2, "max_aspect_num");
1820 lua_pushnumber(L
, (*c
)->size_hints
.max_aspect_den
);
1821 lua_setfield(L
, -2, "max_aspect_den");
1824 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1826 lua_pushnumber(L
, (*c
)->size_hints
.base_width
);
1827 lua_setfield(L
, -2, "base_width");
1828 lua_pushnumber(L
, (*c
)->size_hints
.base_height
);
1829 lua_setfield(L
, -2, "base_height");
1832 if((*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1834 switch((*c
)->size_hints
.win_gravity
)
1837 lua_pushliteral(L
, "north_west");
1839 case XCB_GRAVITY_NORTH
:
1840 lua_pushliteral(L
, "north");
1842 case XCB_GRAVITY_NORTH_EAST
:
1843 lua_pushliteral(L
, "north_east");
1845 case XCB_GRAVITY_WEST
:
1846 lua_pushliteral(L
, "west");
1848 case XCB_GRAVITY_CENTER
:
1849 lua_pushliteral(L
, "center");
1851 case XCB_GRAVITY_EAST
:
1852 lua_pushliteral(L
, "east");
1854 case XCB_GRAVITY_SOUTH_WEST
:
1855 lua_pushliteral(L
, "south_west");
1857 case XCB_GRAVITY_SOUTH
:
1858 lua_pushliteral(L
, "south");
1860 case XCB_GRAVITY_SOUTH_EAST
:
1861 lua_pushliteral(L
, "south_east");
1863 case XCB_GRAVITY_STATIC
:
1864 lua_pushliteral(L
, "static");
1867 lua_setfield(L
, -2, "win_gravity");
1878 /** Get or set mouse buttons bindings for a client.
1879 * \param L The Lua VM state.
1880 * \return The number of element pushed on stack.
1883 * \lparam An array of mouse button bindings objects, or nothing.
1884 * \return The array of mouse button bindings objects of this client.
1887 luaA_client_buttons(lua_State
*L
)
1889 client_t
**client
= luaA_checkudata(L
, 1, "client");
1890 button_array_t
*buttons
= &(*client
)->buttons
;
1892 if(lua_gettop(L
) == 2)
1893 luaA_button_array_set(L
, 2, buttons
);
1895 return luaA_button_array_get(L
, buttons
);
1898 /** Send fake events to a client.
1899 * \param L The Lua VM state.
1900 * \return The number of element pushed on stack.
1903 * \param The event type: key_press, key_release, button_press, button_release
1905 * \param The detail: in case of a key event, this is the keycode to send, in
1906 * case of a button event this is the number of the button. In case of a motion
1907 * event, this is a boolean value which if true make the coordinates relatives.
1908 * \param In case of a motion event, this is the X coordinate.
1909 * \param In case of a motion event, this is the Y coordinate.
1912 luaA_client_fake_input(lua_State
*L
)
1914 if(!globalconf
.have_xtest
)
1916 luaA_warn(L
, "XTest extension is not available, cannot fake input.");
1920 client_t
**c
= luaA_checkudata(L
, 1, "client");
1922 const char *stype
= luaL_checklstring(L
, 2, &tlen
);
1923 uint8_t type
, detail
;
1926 switch(a_tokenize(stype
, tlen
))
1928 case A_TK_KEY_PRESS
:
1929 type
= XCB_KEY_PRESS
;
1930 detail
= luaL_checknumber(L
, 3); /* keycode */
1932 case A_TK_KEY_RELEASE
:
1933 type
= XCB_KEY_RELEASE
;
1934 detail
= luaL_checknumber(L
, 3); /* keycode */
1936 case A_TK_BUTTON_PRESS
:
1937 type
= XCB_BUTTON_PRESS
;
1938 detail
= luaL_checknumber(L
, 3); /* button number */
1940 case A_TK_BUTTON_RELEASE
:
1941 type
= XCB_BUTTON_RELEASE
;
1942 detail
= luaL_checknumber(L
, 3); /* button number */
1944 case A_TK_MOTION_NOTIFY
:
1945 type
= XCB_MOTION_NOTIFY
;
1946 detail
= luaA_checkboolean(L
, 3); /* relative to the current position or not */
1947 x
= luaL_checknumber(L
, 4);
1948 y
= luaL_checknumber(L
, 5);
1954 xcb_test_fake_input(globalconf
.connection
,
1965 * \param L The Lua VM state.
1966 * \return The number of pushed elements.
1969 luaA_client_module_index(lua_State
*L
)
1972 const char *buf
= luaL_checklstring(L
, 2, &len
);
1974 switch(a_tokenize(buf
, len
))
1977 if(globalconf
.screen_focus
->client_focus
)
1978 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1989 /* Client module new index.
1990 * \param L The Lua VM state.
1991 * \return The number of pushed elements.
1994 luaA_client_module_newindex(lua_State
*L
)
1997 const char *buf
= luaL_checklstring(L
, 2, &len
);
2000 switch(a_tokenize(buf
, len
))
2003 c
= luaA_checkudata(L
, 3, "client");
2013 /** Move a client with mouse (DEPRECATED).
2014 * \param L The Lua VM state.
2017 luaA_client_mouse_move(lua_State
*L
)
2019 luaA_deprecate(L
, "awful.mouse.client.move()");
2023 /** Resize a client with mouse (DEPRECATED).
2024 * \param L The Lua VM state.
2025 * \return The number of pushed elements.
2028 luaA_client_mouse_resize(lua_State
*L
)
2030 luaA_deprecate(L
, "awful.mouse.client.resize()");
2034 const struct luaL_reg awesome_client_methods
[] =
2036 { "get", luaA_client_get
},
2037 { "__index", luaA_client_module_index
},
2038 { "__newindex", luaA_client_module_newindex
},
2041 const struct luaL_reg awesome_client_meta
[] =
2043 { "isvisible", luaA_client_isvisible
},
2044 { "geometry", luaA_client_geometry
},
2045 { "buttons", luaA_client_buttons
},
2046 { "tags", luaA_client_tags
},
2047 { "kill", luaA_client_kill
},
2048 { "swap", luaA_client_swap
},
2049 { "raise", luaA_client_raise
},
2050 { "lower", luaA_client_lower
},
2051 { "redraw", luaA_client_redraw
},
2052 { "mouse_resize", luaA_client_mouse_resize
},
2053 { "mouse_move", luaA_client_mouse_move
},
2054 { "unmanage", luaA_client_unmanage
},
2055 { "fake_input", luaA_client_fake_input
},
2056 { "__index", luaA_client_index
},
2057 { "__newindex", luaA_client_newindex
},
2058 { "__eq", luaA_client_eq
},
2059 { "__gc", luaA_client_gc
},
2060 { "__tostring", luaA_client_tostring
},
2064 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80