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/xcb_atom.h>
32 #include "layouts/floating.h"
33 #include "common/markup.h"
34 #include "common/atoms.h"
36 extern awesome_t globalconf
;
38 DO_LUA_NEW(extern, client_t
, client
, "client", client_ref
)
39 DO_LUA_EQ(client_t
, client
, "client")
40 DO_LUA_GC(client_t
, client
, "client", client_unref
)
42 /** Load windows properties, restoring client's tag
43 * and floating state before awesome was restarted if any.
44 * \param c A client pointer.
45 * \param screen A virtual screen.
46 * \return True if client had property, false otherwise.
49 client_loadprops(client_t
* c
, screen_t
*screen
)
52 tag_array_t
*tags
= &screen
->tags
;
54 xcb_get_property_cookie_t floating_q
, fullscreen_q
;
55 xcb_get_property_reply_t
*reply
;
58 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _AWESOME_TAGS
,
62 /* Send the GetProperty requests which will be processed later */
63 floating_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
64 _AWESOME_FLOATING
, CARDINAL
, 0, 1);
66 fullscreen_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
67 _AWESOME_FULLSCREEN
, CARDINAL
, 0, 1);
69 /* ignore property if the tag count isn't matching */
71 for(int i
= 0; i
< tags
->len
; i
++)
73 tag_client(c
, tags
->tab
[i
]);
75 untag_client(c
, tags
->tab
[i
]);
79 /* check for floating */
80 reply
= xcb_get_property_reply(globalconf
.connection
, floating_q
, NULL
);
82 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
83 client_setfloating(c
, *(bool *) data
);
86 /* check for fullscreen */
87 reply
= xcb_get_property_reply(globalconf
.connection
, fullscreen_q
, NULL
);
89 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
90 client_setfullscreen(c
, *(bool *) data
);
96 /** Check if client supports protocol a protocole in WM_PROTOCOL.
97 * \param win The window.
98 * \return True if client has the atom in protocol, false otherwise.
101 window_hasproto(xcb_window_t win
, xcb_atom_t atom
)
104 xcb_get_wm_protocols_reply_t protocols
;
107 if(xcb_get_wm_protocols_reply(globalconf
.connection
,
108 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
112 for(i
= 0; !ret
&& i
< protocols
.atoms_len
; i
++)
113 if(protocols
.atoms
[i
] == atom
)
115 xcb_get_wm_protocols_reply_wipe(&protocols
);
120 /** Returns true if a client is tagged
121 * with one of the tags of the specified screen.
122 * \param c The client to check.
123 * \param screen Virtual screen number.
124 * \return true if the client is visible, false otherwise.
127 client_maybevisible(client_t
*c
, int screen
)
129 if(c
->screen
== screen
)
131 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
134 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
136 for(int i
= 0; i
< tags
->len
; i
++)
137 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
143 /** Get a client by its window.
144 * \param w The client window to find.
145 * \return A client pointer if found, NULL otherwise.
148 client_getbywin(xcb_window_t w
)
151 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
155 /** Unfocus a client.
156 * \param c The client.
159 client_unfocus(client_t
*c
)
161 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
164 luaA_client_userdata_new(globalconf
.L
, c
);
165 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
167 ewmh_update_net_active_window(c
->phys_screen
);
170 /** Ban client and unmap it.
171 * \param c The client.
174 client_ban(client_t
*c
)
176 if(globalconf
.screen_focus
->client_focus
== c
)
178 xcb_unmap_window(globalconf
.connection
, c
->win
);
180 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
182 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
184 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
187 /** Give focus to client, or to first client if client is NULL.
188 * \param c The client or NULL.
189 * \return True if a window (even root) has received focus, false otherwise.
192 client_focus(client_t
*c
)
194 if(!client_maybevisible(c
, c
->screen
) || c
->nofocus
)
197 /* unfocus current selected client */
198 if(globalconf
.screen_focus
->client_focus
199 && c
!= globalconf
.screen_focus
->client_focus
)
200 client_unfocus(globalconf
.screen_focus
->client_focus
);
204 client_setminimized(c
, false);
206 /* unban the client before focusing or it will fail */
209 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
210 globalconf
.screen_focus
->client_focus
= c
;
212 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
213 c
->win
, XCB_CURRENT_TIME
);
215 /* Some layouts use focused client differently, so call them back.
216 * And anyway, we have maybe unhidden */
217 client_need_arrange(c
);
220 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
221 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
223 ewmh_update_net_active_window(c
->phys_screen
);
226 /** Stack a window below.
227 * \param c The client.
228 * \param mode The mode.
229 * \param previous The previous window on the stack.
230 * \param return The next-previous!
233 client_stack_position(client_t
*c
, xcb_stack_mode_t mode
, xcb_window_t previous
)
235 uint32_t config_win_vals
[2];
237 config_win_vals
[0] = previous
;
238 config_win_vals
[1] = mode
;
242 xcb_configure_window(globalconf
.connection
,
243 c
->titlebar
->sw
.window
,
244 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
246 config_win_vals
[0] = c
->titlebar
->sw
.window
;
248 xcb_configure_window(globalconf
.connection
, c
->win
,
249 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
254 /** Stacking layout layers */
257 /** This one is a special layer */
269 /** Get the real layer of a client according to its attribute (fullscreen, …)
270 * \param c The client.
271 * \return The real layer.
274 client_layer_translator(client_t
*c
)
278 else if(c
->isfullscreen
)
279 return LAYER_FULLSCREEN
;
282 else if(c
->isfloating
|| client_isfixed(c
))
284 else if(c
->transient_for
)
285 return LAYER_TRANSIENT_FOR
;
289 case WINDOW_TYPE_DOCK
:
291 case WINDOW_TYPE_DESKTOP
:
292 return LAYER_DESKTOP
;
293 case WINDOW_TYPE_DIALOG
:
301 * \todo It might be worth stopping to restack everyone and only stack `c'
302 * relatively to the first matching in the list.
307 uint32_t config_win_vals
[2];
308 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
312 config_win_vals
[0] = XCB_NONE
;
313 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
315 /* first stack not ontop wibox window */
316 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
317 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
319 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
322 xcb_configure_window(globalconf
.connection
,
324 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
326 config_win_vals
[0] = sb
->sw
.window
;
330 /* stack bottom layers */
331 for(layer
= LAYER_DESKTOP
; layer
< LAYER_FULLSCREEN
; layer
++)
332 for(node
= last
; node
; node
= node
->prev
)
333 if(client_layer_translator(node
->client
) == layer
)
334 config_win_vals
[0] = client_stack_position(node
->client
,
335 XCB_STACK_MODE_ABOVE
,
338 /* then stack ontop wibox window */
339 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
340 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
342 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
345 xcb_configure_window(globalconf
.connection
,
347 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
349 config_win_vals
[0] = sb
->sw
.window
;
353 /* finally stack ontop and fullscreen windows */
354 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
355 for(node
= last
; node
; node
= node
->prev
)
356 if(client_layer_translator(node
->client
) == layer
)
357 config_win_vals
[0] = client_stack_position(node
->client
,
358 XCB_STACK_MODE_ABOVE
,
361 /* stack transient window on top of their parents */
362 for(node
= last
; node
; node
= node
->prev
)
363 if(client_layer_translator(node
->client
) == LAYER_TRANSIENT_FOR
)
364 client_stack_position(node
->client
,
365 XCB_STACK_MODE_ABOVE
,
366 node
->client
->transient_for
->win
);
369 /** Manage a new client.
370 * \param w The window.
371 * \param wgeom Window geometry.
372 * \param phys_screen Physical screen number.
373 * \param screen Virtual screen number where to manage client.
376 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
378 xcb_get_property_cookie_t ewmh_icon_cookie
;
381 const uint32_t select_input_val
[] =
383 XCB_EVENT_MASK_STRUCTURE_NOTIFY
384 | XCB_EVENT_MASK_PROPERTY_CHANGE
385 | XCB_EVENT_MASK_ENTER_WINDOW
388 /* Send request to get NET_WM_ICON property as soon as possible... */
389 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
390 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
392 if(systray_iskdedockapp(w
))
394 systray_request_handle(w
, phys_screen
, NULL
);
398 c
= p_new(client_t
, 1);
400 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
402 c
->phys_screen
= phys_screen
;
406 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
407 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
408 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
409 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
410 client_setborder(c
, wgeom
->border_width
);
411 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
412 c
->icon
= image_ref(&icon
);
414 /* we honor size hints by default */
415 c
->honorsizehints
= true;
418 property_update_wm_normal_hints(c
, NULL
);
419 property_update_wm_hints(c
, NULL
);
420 property_update_wm_transient_for(c
, NULL
);
423 screen
= c
->transient_for
->screen
;
425 /* Try to load props if any */
426 client_loadprops(c
, &globalconf
.screens
[screen
]);
429 /* Then check clients hints */
430 ewmh_client_check_hints(c
);
432 /* move client to screen, but do not tag it for now */
433 screen_client_moveto(c
, screen
, false, true);
435 /* Check if client has been tagged by loading props, or maybe with its
437 * If not, we tag it with current selected ones.
438 * This could be done on Lua side, but it's a sane behaviour. */
442 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
443 for(i
= 0; i
< tags
->len
; i
++)
444 if(is_client_tagged(c
, tags
->tab
[i
]))
447 /* if no tag, set current selected */
449 for(i
= 0; i
< tags
->len
; i
++)
450 if(tags
->tab
[i
]->selected
)
451 tag_client(c
, tags
->tab
[i
]);
454 /* Push client in client list */
455 client_list_push(&globalconf
.clients
, client_ref(&c
));
457 /* Push client in stack */
460 /* update window title */
461 property_update_wm_name(c
);
462 property_update_wm_icon_name(c
);
465 ewmh_client_strut_update(c
, NULL
);
467 ewmh_update_net_client_list(c
->phys_screen
);
469 /* Call hook to notify list change */
470 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
473 luaA_client_userdata_new(globalconf
.L
, c
);
474 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
477 /** Compute client geometry with respect to its geometry hints.
478 * \param c The client.
479 * \param geometry The geometry that the client might receive.
480 * \return The geometry the client must take respecting its hints.
483 client_geometry_hints(client_t
*c
, area_t geometry
)
485 double dx
, dy
, max
, min
, ratio
;
487 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
488 && (geometry
.width
- c
->basew
) > 0)
490 dx
= (double) (geometry
.width
- c
->basew
);
491 dy
= (double) (geometry
.height
- c
->baseh
);
492 min
= (double) (c
->minax
) / (double) (c
->minay
);
493 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
495 if(max
> 0 && min
> 0 && ratio
> 0)
499 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
501 geometry
.width
= (int) dx
+ c
->basew
;
502 geometry
.height
= (int) dy
+ c
->baseh
;
506 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
508 geometry
.width
= (int) dx
+ c
->basew
;
509 geometry
.height
= (int) dy
+ c
->baseh
;
513 if(c
->minw
&& geometry
.width
< c
->minw
)
514 geometry
.width
= c
->minw
;
515 if(c
->minh
&& geometry
.height
< c
->minh
)
516 geometry
.height
= c
->minh
;
517 if(c
->maxw
&& geometry
.width
> c
->maxw
)
518 geometry
.width
= c
->maxw
;
519 if(c
->maxh
&& geometry
.height
> c
->maxh
)
520 geometry
.height
= c
->maxh
;
522 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
524 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
529 /** Resize client window.
530 * \param c Client to resize.
531 * \param geometry New window geometry.
532 * \param hints Use size hints.
535 client_resize(client_t
*c
, area_t geometry
, bool hints
)
539 layout_t
*layout
= layout_get_current(c
->screen
);
541 /* Values to configure a window is an array where values are
542 * stored according to 'value_mask' */
545 if(c
->titlebar
&& !c
->ismoving
&& !client_isfloating(c
) && layout
!= layout_floating
)
546 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
549 geometry
= client_geometry_hints(c
, geometry
);
551 if(geometry
.width
<= 0 || geometry
.height
<= 0)
554 /* offscreen appearance fixes */
555 area
= display_area_get(c
->phys_screen
, NULL
,
556 &globalconf
.screens
[c
->screen
].padding
);
558 fixed
= client_isfixed(c
);
560 if(geometry
.x
> area
.width
)
561 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
562 if(geometry
.y
> area
.height
)
563 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
564 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
566 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
569 /* fixed windows can only change their x,y */
570 if((fixed
&& (c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
))
571 || (!fixed
&& (c
->geometry
.x
!= geometry
.x
572 || c
->geometry
.y
!= geometry
.y
573 || c
->geometry
.width
!= geometry
.width
574 || c
->geometry
.height
!= geometry
.height
)))
576 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
578 c
->geometry
.x
= values
[0] = geometry
.x
;
579 c
->geometry
.width
= values
[2] = geometry
.width
;
580 c
->geometry
.y
= values
[1] = geometry
.y
;
581 c
->geometry
.height
= values
[3] = geometry
.height
;
582 values
[4] = c
->border
;
584 /* save the floating geometry if the window is floating but not
586 if(c
->ismoving
|| client_isfloating(c
)
587 || layout_get_current(new_screen
) == layout_floating
)
589 c
->f_geometry
= geometry
;
591 titlebar_update_geometry_floating(c
);
593 xcb_configure_window(globalconf
.connection
, c
->win
,
594 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
595 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
596 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
598 window_configure(c
->win
, geometry
, c
->border
);
600 if(c
->screen
!= new_screen
)
601 screen_client_moveto(c
, new_screen
, true, false);
604 hooks_property(c
, "geometry");
608 /** Set a clinet floating.
609 * \param c The client.
610 * \param floating Set floating, or not.
611 * \param layer Layer to put the floating window onto.
614 client_setfloating(client_t
*c
, bool floating
)
616 if(c
->isfloating
!= floating
617 && (c
->type
== WINDOW_TYPE_NORMAL
))
619 if((c
->isfloating
= floating
))
621 client_resize(c
, c
->f_geometry
, false);
622 client_need_arrange(c
);
624 xcb_change_property(globalconf
.connection
,
625 XCB_PROP_MODE_REPLACE
,
626 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
629 hooks_property(c
, "floating");
633 /** Set a client minimized, or not.
634 * \param c The client.
635 * \param s Set or not the client minimized.
638 client_setminimized(client_t
*c
, bool s
)
640 if(c
->isminimized
!= s
)
642 client_need_arrange(c
);
644 client_need_arrange(c
);
645 ewmh_client_update_hints(c
);
647 hooks_property(c
, "minimized");
651 /** Set a client sticky, or not.
652 * \param c The client.
653 * \param s Set or not the client sticky.
656 client_setsticky(client_t
*c
, bool s
)
660 client_need_arrange(c
);
662 client_need_arrange(c
);
663 ewmh_client_update_hints(c
);
664 hooks_property(c
, "sticky");
668 /** Set a client fullscreen, or not.
669 * \param c The client.
670 * \param s Set or not the client fullscreen.
673 client_setfullscreen(client_t
*c
, bool s
)
675 if(c
->isfullscreen
!= s
)
679 /* become fullscreen! */
680 if((c
->isfullscreen
= s
))
682 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
683 c
->m_geometry
= c
->geometry
;
684 c
->oldborder
= c
->border
;
685 client_setborder(c
, 0);
689 geometry
= c
->m_geometry
;
690 client_setborder(c
, c
->oldborder
);
691 client_resize(c
, c
->m_geometry
, false);
693 client_resize(c
, geometry
, false);
694 client_need_arrange(c
);
696 xcb_change_property(globalconf
.connection
,
697 XCB_PROP_MODE_REPLACE
,
698 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
700 ewmh_client_update_hints(c
);
701 hooks_property(c
, "fullscreen");
705 /** Set a client above, or not.
706 * \param c The client.
707 * \param s Set or not the client above.
710 client_setabove(client_t
*c
, bool s
)
716 ewmh_client_update_hints(c
);
718 hooks_property(c
, "above");
722 /** Set a client below, or not.
723 * \param c The client.
724 * \param s Set or not the client below.
727 client_setbelow(client_t
*c
, bool s
)
733 ewmh_client_update_hints(c
);
735 hooks_property(c
, "below");
739 /** Set a client modal, or not.
740 * \param c The client.
741 * \param s Set or not the client moda.
744 client_setmodal(client_t
*c
, bool s
)
750 ewmh_client_update_hints(c
);
752 hooks_property(c
, "modal");
756 /** Set a client ontop, or not.
757 * \param c The client.
758 * \param s Set or not the client moda.
761 client_setontop(client_t
*c
, bool s
)
768 hooks_property(c
, "ontop");
772 /** Save client properties as an X property.
773 * \param c The client.
776 client_saveprops_tags(client_t
*c
)
778 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
779 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
782 for(i
= 0; i
< tags
->len
; i
++)
783 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
785 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
789 * \param c The client.
792 client_unban(client_t
*c
)
794 xcb_map_window(globalconf
.connection
, c
->win
);
795 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
798 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
799 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
801 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
805 /** Unmanage a client.
806 * \param c The client.
809 client_unmanage(client_t
*c
)
811 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
813 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
816 /* remove client everywhere */
817 client_list_detach(&globalconf
.clients
, c
);
818 stack_client_delete(c
);
819 for(int i
= 0; i
< tags
->len
; i
++)
820 untag_client(c
, tags
->tab
[i
]);
823 luaA_client_userdata_new(globalconf
.L
, c
);
824 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
826 /* Call hook to notify list change */
827 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
829 /* The server grab construct avoids race conditions. */
830 xcb_grab_server(globalconf
.connection
);
832 xcb_configure_window(globalconf
.connection
, c
->win
,
833 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
834 (uint32_t *) &c
->oldborder
);
836 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
837 XCB_BUTTON_MASK_ANY
);
838 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
840 xcb_flush(globalconf
.connection
);
841 xcb_ungrab_server(globalconf
.connection
);
843 titlebar_client_detach(c
);
845 ewmh_update_net_client_list(c
->phys_screen
);
847 /* delete properties */
848 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
849 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
851 if(client_hasstrut(c
))
852 /* All the wiboxes (may) need to be repositioned */
853 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
854 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
856 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
857 wibox_position_update(s
);
860 /* set client as invalid */
866 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
868 * \param c The client to kill.
871 client_kill(client_t
*c
)
873 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
875 xcb_client_message_event_t ev
;
877 /* Initialize all of event's fields first */
880 ev
.response_type
= XCB_CLIENT_MESSAGE
;
883 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
884 ev
.type
= WM_PROTOCOLS
;
885 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
887 xcb_send_event(globalconf
.connection
, false, c
->win
,
888 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
891 xcb_kill_client(globalconf
.connection
, c
->win
);
894 /** Get all clients into a table.
895 * \param L The Lua VM state.
896 * \return The number of elements pushed on stack.
898 * \lparam An optional screen nunmber.
899 * \lreturn A table with all clients.
902 luaA_client_get(lua_State
*L
)
907 screen
= luaL_optnumber(L
, 1, 0) - 1;
911 if(screen
== SCREEN_UNDEF
)
912 for(c
= globalconf
.clients
; c
; c
= c
->next
)
914 luaA_client_userdata_new(globalconf
.L
, c
);
915 lua_rawseti(L
, -2, i
++);
919 luaA_checkscreen(screen
);
920 for(c
= globalconf
.clients
; c
; c
= c
->next
)
921 if(c
->screen
== screen
)
923 luaA_client_userdata_new(globalconf
.L
, c
);
924 lua_rawseti(L
, -2, i
++);
931 /** Get only visible clients for a screen (DEPRECATED).
932 * \param L The Lua VM state.
933 * \return The number of elements pushed on stack.
935 * \lparam A screen number.
936 * \lreturn A table with all visible clients for this screen.
939 luaA_client_visible_get(lua_State
*L
)
943 int screen
= luaL_checknumber(L
, 1) - 1;
945 luaA_checkscreen(screen
);
951 for(c
= globalconf
.clients
; c
; c
= c
->next
)
952 if(client_isvisible(c
, screen
))
954 luaA_client_userdata_new(L
, c
);
955 lua_rawseti(L
, -2, i
++);
961 /** Check if a client is visible on its screen.
962 * \param L The Lua VM state.
963 * \return The number of elements pushed on stack.
966 * \lreturn A boolean value, true if the client is visible, false otherwise.
969 luaA_client_isvisible(lua_State
*L
)
971 client_t
**c
= luaA_checkudata(L
, 1, "client");
972 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
976 /** Set client border width.
977 * \param c The client.
978 * \param width The border width.
981 client_setborder(client_t
*c
, int width
)
985 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
986 || c
->type
== WINDOW_TYPE_SPLASH
987 || c
->type
== WINDOW_TYPE_DESKTOP
991 if(width
== c
->border
|| width
< 0)
995 xcb_configure_window(globalconf
.connection
, c
->win
,
996 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
998 if(client_isvisible(c
, c
->screen
))
1000 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1001 titlebar_update_geometry_floating(c
);
1003 globalconf
.screens
[c
->screen
].need_arrange
= true;
1006 hooks_property(c
, "border_width");
1010 * \param L The Lua VM state.
1016 luaA_client_kill(lua_State
*L
)
1018 client_t
**c
= luaA_checkudata(L
, 1, "client");
1023 /** Swap a client with another one.
1024 * \param L The Lua VM state.
1027 * \lparam A client to swap with.
1030 luaA_client_swap(lua_State
*L
)
1032 client_t
**c
= luaA_checkudata(L
, 1, "client");
1033 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1034 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1035 client_need_arrange(*c
);
1036 client_need_arrange(*swap
);
1038 /* Call hook to notify list change */
1039 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1044 /** Access or set the client tags.
1045 * \param L The Lua VM state.
1046 * \return The number of elements pushed on stack.
1047 * \lparam A table with tags to set, or none to get the current tags table.
1048 * \return The clients tag.
1051 luaA_client_tags(lua_State
*L
)
1055 client_t
**c
= luaA_checkudata(L
, 1, "client");
1058 if(lua_gettop(L
) == 2)
1060 luaA_checktable(L
, 2);
1061 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1062 for(int i
= 0; i
< tags
->len
; i
++)
1063 untag_client(*c
, tags
->tab
[i
]);
1065 while(lua_next(L
, 2))
1067 tag
= luaA_checkudata(L
, -1, "tag");
1068 tag_client(*c
, *tag
);
1074 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1076 for(int i
= 0; i
< tags
->len
; i
++)
1077 if(is_client_tagged(*c
, tags
->tab
[i
]))
1079 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1080 lua_rawseti(L
, -2, ++j
);
1086 /** Raise a client on top of others which are on the same layer.
1087 * \param L The Lua VM state.
1093 luaA_client_raise(lua_State
*L
)
1095 client_t
**c
= luaA_checkudata(L
, 1, "client");
1100 /** Redraw a client by unmapping and mapping it quickly.
1101 * \param L The Lua VM state.
1107 luaA_client_redraw(lua_State
*L
)
1109 client_t
**c
= luaA_checkudata(L
, 1, "client");
1111 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1112 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1114 /* Set the focus on the current window if the redraw has been
1115 performed on the window where the pointer is currently on
1116 because after the unmapping/mapping, the focus is lost */
1117 if(globalconf
.screen_focus
->client_focus
== *c
)
1118 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1119 (*c
)->win
, XCB_CURRENT_TIME
);
1124 /** Stop managing a client.
1125 * \param L The Lua VM state.
1126 * \return The number of elements pushed on stack.
1131 luaA_client_unmanage(lua_State
*L
)
1133 client_t
**c
= luaA_checkudata(L
, 1, "client");
1134 client_unmanage(*c
);
1138 /** Return client geometry.
1139 * \param L The Lua VM state.
1140 * \return The number of elements pushed on stack.
1142 * \lparam A table with new coordinates, or none.
1143 * \lreturn A table with client coordinates.
1146 luaA_client_geometry(lua_State
*L
)
1148 client_t
**c
= luaA_checkudata(L
, 1, "client");
1150 if(lua_gettop(L
) == 2)
1152 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1156 luaA_checktable(L
, 2);
1157 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1158 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1159 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1160 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1161 client_resize(*c
, geometry
, false);
1165 return luaA_pusharea(L
, (*c
)->geometry
);
1169 luaA_client_coords(lua_State
*L
)
1172 return luaA_client_geometry(L
);
1175 /** Return client geometry, using also titlebar and border width.
1176 * \param L The Lua VM state.
1177 * \return The number of elements pushed on stack.
1179 * \lparam A table with new coordinates, or none.
1180 * \lreturn A table with client coordinates.
1183 luaA_client_fullgeometry(lua_State
*L
)
1185 client_t
**c
= luaA_checkudata(L
, 1, "client");
1188 if(lua_gettop(L
) == 2)
1190 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1192 luaA_checktable(L
, 2);
1193 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1194 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1195 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1196 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1197 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1200 client_resize(*c
, geometry
, false);
1204 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1210 luaA_client_fullcoords(lua_State
*L
)
1213 return luaA_client_fullgeometry(L
);
1216 /** Client newindex.
1217 * \param L The Lua VM state.
1218 * \return The number of elements pushed on stack.
1221 luaA_client_newindex(lua_State
*L
)
1224 client_t
**c
= luaA_checkudata(L
, 1, "client");
1225 const char *buf
= luaL_checklstring(L
, 2, &len
);
1233 luaL_error(L
, "client is invalid\n");
1235 switch(a_tokenize(buf
, len
))
1238 if(globalconf
.xinerama_is_active
)
1240 i
= luaL_checknumber(L
, 3) - 1;
1241 luaA_checkscreen(i
);
1242 if(i
!= (*c
)->screen
)
1243 screen_client_moveto(*c
, i
, true, true);
1247 b
= luaA_checkboolean(L
, 3);
1248 if(b
!= (*c
)->ishidden
)
1250 client_need_arrange(*c
);
1252 client_need_arrange(*c
);
1256 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1258 case A_TK_FULLSCREEN
:
1259 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1262 image
= luaA_checkudata(L
, 3, "image");
1263 image_unref(&(*c
)->icon
);
1265 (*c
)->icon
= *image
;
1267 hooks_property(*c
, "icon");
1271 window_opacity_set((*c
)->win
, -1);
1274 d
= luaL_checknumber(L
, 3);
1275 if(d
>= 0 && d
<= 1)
1276 window_opacity_set((*c
)->win
, d
);
1280 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1283 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1285 case A_TK_HONORSIZEHINTS
:
1286 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1287 client_need_arrange(*c
);
1289 case A_TK_BORDER_WIDTH
:
1290 client_setborder(*c
, luaL_checknumber(L
, 3));
1293 client_setontop(*c
, luaA_checkboolean(L
, 3));
1295 case A_TK_BORDER_COLOR
:
1296 if((buf
= luaL_checklstring(L
, 3, &len
))
1297 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1298 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1299 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1303 titlebar_client_detach(*c
);
1306 t
= luaA_checkudata(L
, 3, "wibox");
1307 titlebar_client_attach(*c
, *t
);
1318 * \param L The Lua VM state.
1319 * \return The number of elements pushed on stack.
1321 * \lfield name The client title.
1322 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1323 * \lfield type The window type (desktop, normal, dock, …).
1324 * \lfield class The client class.
1325 * \lfield instance The client instance.
1326 * \lfield pid The client PID, if available.
1327 * \lfield role The window role, if available.
1328 * \lfield machine The machine client is running on.
1329 * \lfield icon_name The client name when iconified.
1330 * \lfield screen Client screen number.
1331 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1332 * invisible in taskbar.
1333 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1335 * \lfield icon_path Path to the icon used to identify.
1336 * \lfield floating True always floating.
1337 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1338 * \lfield border_width The client border width.
1339 * \lfield border_color The client border color.
1340 * \lfield titlebar The client titlebar.
1341 * \lfield urgent The client urgent state.
1342 * \lfield focus The focused client.
1343 * \lfield opacity The client opacity between 0 and 1.
1344 * \lfield ontop The client is on top of every other windows.
1345 * \lfield fullscreen The client is fullscreen or not.
1348 luaA_client_index(lua_State
*L
)
1352 client_t
**c
= luaA_checkudata(L
, 1, "client");
1353 const char *buf
= luaL_checklstring(L
, 2, &len
);
1356 xcb_get_wm_class_reply_t hint
;
1357 xcb_get_property_cookie_t prop_c
;
1358 xcb_get_property_reply_t
*prop_r
= NULL
;
1362 luaL_error(L
, "client is invalid\n");
1364 if(luaA_usemetatable(L
, 1, 2))
1367 switch(a_tokenize(buf
, len
))
1370 lua_pushstring(L
, (*c
)->name
);
1372 case A_TK_SKIP_TASKBAR
:
1373 lua_pushboolean(L
, (*c
)->skiptb
);
1378 case WINDOW_TYPE_DESKTOP
:
1379 lua_pushliteral(L
, "desktop");
1381 case WINDOW_TYPE_DOCK
:
1382 lua_pushliteral(L
, "dock");
1384 case WINDOW_TYPE_SPLASH
:
1385 lua_pushliteral(L
, "splash");
1387 case WINDOW_TYPE_DIALOG
:
1388 lua_pushliteral(L
, "dialog");
1391 lua_pushliteral(L
, "normal");
1396 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1397 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1400 lua_pushstring(L
, hint
.class);
1401 xcb_get_wm_class_reply_wipe(&hint
);
1404 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1405 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1408 lua_pushstring(L
, hint
.name
);
1409 xcb_get_wm_class_reply_wipe(&hint
);
1412 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1413 WM_WINDOW_ROLE
, &value
, &slen
))
1415 lua_pushlstring(L
, value
, slen
);
1419 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1420 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1422 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1423 lua_pushnumber(L
, *(uint32_t *)data
);
1431 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1432 WM_CLIENT_MACHINE
, &value
, &slen
))
1434 lua_pushlstring(L
, value
, slen
);
1437 case A_TK_ICON_NAME
:
1438 lua_pushstring(L
, (*c
)->icon_name
);
1441 lua_pushnumber(L
, 1 + (*c
)->screen
);
1444 lua_pushboolean(L
, (*c
)->ishidden
);
1447 lua_pushboolean(L
, (*c
)->isminimized
);
1449 case A_TK_FULLSCREEN
:
1450 lua_pushboolean(L
, (*c
)->isfullscreen
);
1454 luaA_image_userdata_new(L
, (*c
)->icon
);
1459 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1460 lua_pushnumber(L
, d
);
1465 lua_pushboolean(L
, (*c
)->isfloating
);
1468 lua_pushboolean(L
, (*c
)->isontop
);
1471 lua_pushboolean(L
, (*c
)->issticky
);
1473 case A_TK_HONORSIZEHINTS
:
1474 lua_pushboolean(L
, (*c
)->honorsizehints
);
1476 case A_TK_BORDER_WIDTH
:
1477 lua_pushnumber(L
, (*c
)->border
);
1479 case A_TK_BORDER_COLOR
:
1480 luaA_pushcolor(L
, &(*c
)->border_color
);
1484 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1487 lua_pushboolean(L
, (*c
)->isurgent
);
1489 case A_TK_SIZEHINTS
:
1491 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1492 lua_setfield(L
, -2, "user_position");
1493 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1494 lua_setfield(L
, -2, "user_size");
1495 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1496 lua_setfield(L
, -2, "program_position");
1497 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1498 lua_setfield(L
, -2, "program_size");
1507 /** Get or set mouse buttons bindings for a client.
1508 * \param L The Lua VM state.
1509 * \return The number of element pushed on stack.
1512 * \lparam An array of mouse button bindings objects, or nothing.
1513 * \return The array of mouse button bindings objects of this client.
1516 luaA_client_buttons(lua_State
*L
)
1518 client_t
**client
= luaA_checkudata(L
, 1, "client");
1519 button_array_t
*buttons
= &(*client
)->buttons
;
1521 if(lua_gettop(L
) == 2)
1522 luaA_button_array_set(L
, 2, buttons
);
1524 return luaA_button_array_get(L
, buttons
);
1528 * \param L The Lua VM state.
1529 * \return The number of pushed elements.
1532 luaA_client_module_index(lua_State
*L
)
1535 const char *buf
= luaL_checklstring(L
, 2, &len
);
1537 switch(a_tokenize(buf
, len
))
1540 if(globalconf
.screen_focus
->client_focus
)
1541 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1552 /* Client module new index.
1553 * \param L The Lua VM state.
1554 * \return The number of pushed elements.
1557 luaA_client_module_newindex(lua_State
*L
)
1560 const char *buf
= luaL_checklstring(L
, 2, &len
);
1563 switch(a_tokenize(buf
, len
))
1566 c
= luaA_checkudata(L
, 3, "client");
1576 const struct luaL_reg awesome_client_methods
[] =
1578 { "get", luaA_client_get
},
1579 { "visible_get", luaA_client_visible_get
},
1580 { "__index", luaA_client_module_index
},
1581 { "__newindex", luaA_client_module_newindex
},
1584 const struct luaL_reg awesome_client_meta
[] =
1586 { "isvisible", luaA_client_isvisible
},
1587 { "geometry", luaA_client_geometry
},
1588 { "fullgeometry", luaA_client_fullgeometry
},
1589 { "buttons", luaA_client_buttons
},
1590 { "tags", luaA_client_tags
},
1591 { "kill", luaA_client_kill
},
1592 { "swap", luaA_client_swap
},
1593 { "raise", luaA_client_raise
},
1594 { "redraw", luaA_client_redraw
},
1595 { "mouse_resize", luaA_client_mouse_resize
},
1596 { "mouse_move", luaA_client_mouse_move
},
1597 { "unmanage", luaA_client_unmanage
},
1598 { "__index", luaA_client_index
},
1599 { "__newindex", luaA_client_newindex
},
1600 { "__eq", luaA_client_eq
},
1601 { "__gc", luaA_client_gc
},
1602 { "__tostring", luaA_client_tostring
},
1604 { "coords", luaA_client_coords
},
1605 { "fullcoords", luaA_client_fullcoords
},
1609 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80