2 * client.c - client management
4 * Copyright © 2007-2009 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>
23 #include <xcb/xcb_image.h>
32 #include "common/atoms.h"
33 #include "common/xutil.h"
35 DO_LUA_TOSTRING(client_t
, client
, "client")
38 luaA_client_checkudata(lua_State
*L
, int ud
)
40 client_t
*c
= luaL_checkudata(L
, ud
, "client");
42 luaL_error(L
, "client is invalid\n");
47 * \param L The Lua VM state.
48 * \return The number of element pushed on stack.
51 luaA_client_gc(lua_State
*L
)
53 client_t
*c
= luaL_checkudata(L
, 1, "client");
54 luaA_ref_array_wipe(&c
->refs
);
55 button_array_wipe(&c
->buttons
);
56 image_unref(L
, c
->icon
);
58 p_delete(&c
->startup_id
);
59 p_delete(&c
->instance
);
60 p_delete(&c
->icon_name
);
65 /** Change the clients urgency flag.
67 * \param urgent The new flag state
70 client_seturgent(client_t
*c
, bool urgent
)
72 if(c
->isurgent
!= urgent
)
74 xcb_get_property_cookie_t hints
=
75 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
78 ewmh_client_update_hints(c
);
80 /* update ICCCM hints */
82 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
85 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
87 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
89 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
91 hooks_property(c
, "urgent");
95 /** Returns true if a client is tagged
96 * with one of the tags of the specified screen.
97 * \param c The client to check.
98 * \param screen Virtual screen.
99 * \return true if the client is visible, false otherwise.
102 client_maybevisible(client_t
*c
, screen_t
*screen
)
104 if(c
->screen
== screen
)
106 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
109 foreach(tag
, screen
->tags
)
110 if((*tag
)->selected
&& is_client_tagged(c
, *tag
))
116 /** Return the content of a client as an image.
117 * That's just take a screenshot.
118 * \param c The client.
119 * \return 1 if the image has been pushed on stack, false otherwise.
122 client_getcontent(client_t
*c
)
124 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
127 c
->geometries
.internal
.width
,
128 c
->geometries
.internal
.height
,
129 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
134 if(ximage
->bpp
>= 24)
136 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
138 for(int y
= 0; y
< ximage
->height
; y
++)
139 for(int x
= 0; x
< ximage
->width
; x
++)
141 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
142 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
145 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
147 xcb_image_destroy(ximage
);
153 /** Get a client by its window.
154 * \param w The client window to find.
155 * \return A client pointer if found, NULL otherwise.
158 client_getbywin(xcb_window_t w
)
160 foreach(c
, globalconf
.clients
)
167 /** Record that a client lost focus.
168 * \param c Client being unfocused
171 client_unfocus_update(client_t
*c
)
173 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
174 ewmh_update_net_active_window(c
->phys_screen
);
177 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
179 client_push(globalconf
.L
, c
);
180 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
185 /** Unfocus a client.
186 * \param c The client.
189 client_unfocus(client_t
*c
)
192 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
193 /* Set focus on root window, so no events leak to the current window. */
194 window_setfocus(root_win
, true);
196 client_unfocus_update(c
);
199 /** Ban client and move it out of the viewport.
200 * \param c The client.
203 client_ban(client_t
*c
)
207 /* Move all clients out of the physical viewport into negative coordinate space. */
208 /* They will all be put on top of each other. */
209 uint32_t request
[2] = { - (c
->geometries
.internal
.width
+ 2 * c
->border
),
210 - (c
->geometries
.internal
.height
+ 2 * c
->border
) };
212 xcb_configure_window(globalconf
.connection
, c
->win
,
213 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
218 /* All the wiboxes (may) need to be repositioned. */
219 if(client_hasstrut(c
))
220 wibox_update_positions();
222 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
223 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
225 /* Wait until the last moment to take away the focus from the window. */
226 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
231 /** Record that a client got focus.
232 * \param c Client being focused.
235 client_focus_update(client_t
*c
)
237 if(!client_maybevisible(c
, c
->screen
))
239 /* Focus previously focused client */
240 client_focus(globalconf
.screen_focus
->prev_client_focus
);
244 if(globalconf
.screen_focus
245 && globalconf
.screen_focus
->client_focus
)
247 if (globalconf
.screen_focus
->client_focus
!= c
)
248 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
250 /* Already focused */
253 /* stop hiding client */
255 client_setminimized(c
, false);
257 /* unban the client before focusing for consistency */
260 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
261 globalconf
.screen_focus
->prev_client_focus
= c
;
262 globalconf
.screen_focus
->client_focus
= c
;
264 /* Some layouts use focused client differently, so call them back.
265 * And anyway, we have maybe unhidden */
266 client_need_arrange(c
);
268 /* according to EWMH, we have to remove the urgent state from a client */
269 client_seturgent(c
, false);
271 ewmh_update_net_active_window(c
->phys_screen
);
274 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
276 client_push(globalconf
.L
, c
);
277 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
282 /** Give focus to client, or to first client if client is NULL.
283 * \param c The client or NULL.
286 client_focus(client_t
*c
)
288 /* We have to set focus on first client */
289 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
292 if(!client_maybevisible(c
, c
->screen
))
296 client_focus_update(c
);
298 window_setfocus(c
->win
, !c
->nofocus
);
301 /** Stack a window below.
302 * \param c The client.
303 * \param previous The previous window on the stack.
304 * \param return The next-previous!
307 client_stack_above(client_t
*c
, xcb_window_t previous
)
309 uint32_t config_win_vals
[2];
311 config_win_vals
[0] = previous
;
312 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
314 xcb_configure_window(globalconf
.connection
, c
->win
,
315 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
318 config_win_vals
[0] = c
->win
;
322 xcb_configure_window(globalconf
.connection
,
323 c
->titlebar
->sw
.window
,
324 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
326 previous
= c
->titlebar
->sw
.window
;
331 /* stack transient window on top of their parents */
332 foreach(node
, globalconf
.stack
)
333 if((*node
)->transient_for
== c
)
334 previous
= client_stack_above(*node
, previous
);
339 /** Stacking layout layers */
342 /** This one is a special layer */
350 /** This one only used for counting and is not a real layer */
354 /** Get the real layer of a client according to its attribute (fullscreen, …)
355 * \param c The client.
356 * \return The real layer.
359 client_layer_translator(client_t
*c
)
361 /* first deal with user set attributes */
364 else if(c
->isfullscreen
)
365 return LAYER_FULLSCREEN
;
371 /* check for transient attr */
375 /* then deal with windows type */
378 case WINDOW_TYPE_DESKTOP
:
379 return LAYER_DESKTOP
;
388 * \todo It might be worth stopping to restack everyone and only stack `c'
389 * relatively to the first matching in the list.
392 client_real_stack(void)
394 uint32_t config_win_vals
[2];
397 config_win_vals
[0] = XCB_NONE
;
398 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
400 /* stack desktop windows */
401 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
402 foreach(node
, globalconf
.stack
)
403 if(client_layer_translator(*node
) == layer
)
404 config_win_vals
[0] = client_stack_above(*node
,
407 /* first stack not ontop wibox window */
408 foreach(s
, globalconf
.screens
)
409 foreach(_sb
, s
->wiboxes
)
414 xcb_configure_window(globalconf
.connection
,
416 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
418 config_win_vals
[0] = sb
->sw
.window
;
422 /* then stack clients */
423 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
424 foreach(node
, globalconf
.stack
)
425 if(client_layer_translator(*node
) == layer
)
426 config_win_vals
[0] = client_stack_above(*node
,
429 /* then stack ontop wibox window */
430 foreach(s
, globalconf
.screens
)
431 foreach(_sb
, s
->wiboxes
)
436 xcb_configure_window(globalconf
.connection
,
438 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
440 config_win_vals
[0] = sb
->sw
.window
;
446 client_stack_refresh()
448 if (!globalconf
.client_need_stack_refresh
)
450 globalconf
.client_need_stack_refresh
= false;
454 /** Manage a new client.
455 * \param w The window.
456 * \param wgeom Window geometry.
457 * \param phys_screen Physical screen number.
458 * \param startup True if we are managing at startup time.
461 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
463 xcb_get_property_cookie_t ewmh_icon_cookie
;
464 client_t
*c
, *tc
= NULL
;
466 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
468 if(systray_iskdedockapp(w
))
470 systray_request_handle(w
, phys_screen
, NULL
);
474 /* Send request to get NET_WM_ICON property as soon as possible... */
475 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
476 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
478 c
= client_new(globalconf
.L
);
479 /* Push client in client list */
480 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
));
483 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
486 c
->phys_screen
= phys_screen
;
490 c
->geometry
.x
= wgeom
->x
;
491 c
->geometry
.y
= wgeom
->y
;
492 /* Border will be added later. */
493 c
->geometry
.width
= wgeom
->width
;
494 c
->geometry
.height
= wgeom
->height
;
495 /* Also set internal geometry (client_ban() needs it). */
496 c
->geometries
.internal
.x
= wgeom
->x
;
497 c
->geometries
.internal
.y
= wgeom
->y
;
498 c
->geometries
.internal
.width
= wgeom
->width
;
499 c
->geometries
.internal
.height
= wgeom
->height
;
500 client_setborder(c
, wgeom
->border_width
);
502 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
503 c
->icon
= image_ref(globalconf
.L
);
505 /* we honor size hints by default */
506 c
->size_hints_honor
= true;
509 property_update_wm_normal_hints(c
, NULL
);
510 property_update_wm_hints(c
, NULL
);
511 property_update_wm_transient_for(c
, NULL
);
512 property_update_wm_client_leader(c
, NULL
);
514 /* Recursively find the parent. */
515 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
516 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
519 /* Then check clients hints */
520 ewmh_client_check_hints(c
);
522 /* move client to screen, but do not tag it */
523 screen_client_moveto(c
, screen
, false, true);
525 /* Push client in stack */
528 /* update window title */
529 property_update_wm_name(c
);
530 property_update_wm_icon_name(c
);
531 property_update_wm_class(c
, NULL
);
533 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
536 ewmh_process_client_strut(c
, NULL
);
538 ewmh_update_net_client_list(c
->phys_screen
);
540 /* Always stay in NORMAL_STATE. Even though iconified seems more
541 * appropriate sometimes. The only possible loss is that clients not using
542 * visibility events may continue to proces data (when banned).
543 * Without any exposes or other events the cost should be fairly limited though.
545 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
546 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
548 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
549 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
551 * "Once a client's window has left the Withdrawn state, the window will be mapped
552 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
554 * At this stage it's just safer to keep it in normal state and avoid confusion.
556 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
558 /* Move window outside the viewport before mapping it. */
560 xcb_map_window(globalconf
.connection
, c
->win
);
563 spawn_start_notify(c
);
565 /* Call hook to notify list change */
566 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
567 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
570 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
572 client_push(globalconf
.L
, c
);
573 lua_pushboolean(globalconf
.L
, startup
);
574 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
578 /** Compute client geometry with respect to its geometry hints.
579 * \param c The client.
580 * \param geometry The geometry that the client might receive.
581 * \return The geometry the client must take respecting its hints.
584 client_geometry_hints(client_t
*c
, area_t geometry
)
586 int32_t basew
, baseh
, minw
, minh
;
588 /* base size is substituted with min size if not specified */
589 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
591 basew
= c
->size_hints
.base_width
;
592 baseh
= c
->size_hints
.base_height
;
594 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
596 basew
= c
->size_hints
.min_width
;
597 baseh
= c
->size_hints
.min_height
;
602 /* min size is substituted with base size if not specified */
603 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
605 minw
= c
->size_hints
.min_width
;
606 minh
= c
->size_hints
.min_height
;
608 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
610 minw
= c
->size_hints
.base_width
;
611 minh
= c
->size_hints
.base_height
;
616 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
617 && c
->size_hints
.min_aspect_num
> 0
618 && c
->size_hints
.min_aspect_den
> 0
619 && geometry
.height
- baseh
> 0
620 && geometry
.width
- basew
> 0)
622 double dx
= (double) (geometry
.width
- basew
);
623 double dy
= (double) (geometry
.height
- baseh
);
624 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
625 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
626 double ratio
= dx
/ dy
;
627 if(max
> 0 && min
> 0 && ratio
> 0)
631 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
633 geometry
.width
= (int) dx
+ basew
;
634 geometry
.height
= (int) dy
+ baseh
;
638 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
640 geometry
.width
= (int) dx
+ basew
;
641 geometry
.height
= (int) dy
+ baseh
;
647 geometry
.width
= MAX(geometry
.width
, minw
);
649 geometry
.height
= MAX(geometry
.height
, minh
);
651 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
653 if(c
->size_hints
.max_width
)
654 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
655 if(c
->size_hints
.max_height
)
656 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
659 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
660 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
662 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
663 unsigned_subtract(t1
, basew
);
664 unsigned_subtract(t2
, baseh
);
665 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
666 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
672 /** Resize client window.
673 * The sizse given as parameters are with titlebar and borders!
674 * \param c Client to resize.
675 * \param geometry New window geometry.
676 * \param hints Use size hints.
677 * \return true if an actual resize occurred.
680 client_resize(client_t
*c
, area_t geometry
, bool hints
)
682 area_t geometry_internal
;
685 /* offscreen appearance fixes */
686 area
= display_area_get(c
->phys_screen
, NULL
,
687 &c
->screen
->padding
);
689 if(geometry
.x
> area
.width
)
690 geometry
.x
= area
.width
- geometry
.width
;
691 if(geometry
.y
> area
.height
)
692 geometry
.y
= area
.height
- geometry
.height
;
693 if(geometry
.x
+ geometry
.width
< 0)
695 if(geometry
.y
+ geometry
.height
< 0)
698 /* Real client geometry, please keep it contained to C code at the very least. */
699 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
702 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
704 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
707 /* Also let client hints propegate to the "official" geometry. */
708 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
710 if(c
->geometries
.internal
.x
!= geometry_internal
.x
711 || c
->geometries
.internal
.y
!= geometry_internal
.y
712 || c
->geometries
.internal
.width
!= geometry_internal
.width
713 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
715 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
716 geometry_internal
.x
, geometry_internal
.y
);
718 /* Values to configure a window is an array where values are
719 * stored according to 'value_mask' */
722 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
723 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
724 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
725 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
727 /* Also store geometry including border and titlebar. */
728 c
->geometry
= geometry
;
730 titlebar_update_geometry(c
);
732 /* The idea is to give a client a resize even when banned. */
733 /* We just have to move the (x,y) to keep it out of the viewport. */
734 /* This at least doesn't break expectations about events. */
737 geometry_internal
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
738 geometry_internal
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
741 xcb_configure_window(globalconf
.connection
, c
->win
,
742 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
743 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
746 screen_client_moveto(c
, new_screen
, true, false);
749 hooks_property(c
, "geometry");
757 /** Update the position of all window with struts on a specific screen.
758 * \param screen The screen that should be processed.
761 client_update_strut_positions(screen_t
*screen
)
763 area_t allowed_area
, geom
;
765 /* Ignore all struts for starters. */
766 foreach(_c
, globalconf
.clients
)
769 if(c
->screen
== screen
&& client_hasstrut(c
))
770 c
->ignore_strut
= true;
774 * Top and bottom panels are common, so they take precendence.
775 * WINDOW_TYPE_DOCK really wants to be at the side, so choose them first.
778 /* WINDOW_TYPE_DOCK: top + bottom. */
779 foreach(_c
, globalconf
.clients
)
782 if(c
->screen
!= screen
|| !client_hasstrut(c
) || c
->type
!= WINDOW_TYPE_DOCK
)
785 /* Screen area, minus padding, wibox'es and already processed struts. */
786 allowed_area
= screen_area_get(c
->screen
,
793 if(c
->strut
.top
|| c
->strut
.top_start_x
|| c
->strut
.top_end_x
)
795 geom
.y
= allowed_area
.y
;
796 if(geom
.x
< allowed_area
.x
797 || geom
.x
+ geom
.width
> allowed_area
.x
+ allowed_area
.width
)
799 geom
.x
= allowed_area
.x
;
800 if(geom
.width
> allowed_area
.width
)
801 geom
.width
= allowed_area
.width
;
803 c
->ignore_strut
= false;
804 client_resize(c
, geom
, false);
806 else if(c
->strut
.bottom
|| c
->strut
.bottom_start_x
|| c
->strut
.bottom_end_x
)
808 geom
.y
= allowed_area
.y
+ allowed_area
.height
- geom
.height
;
809 if(geom
.x
< allowed_area
.x
810 || geom
.x
+ geom
.width
> allowed_area
.x
+ allowed_area
.width
)
812 geom
.x
= allowed_area
.x
;
813 if(geom
.width
> allowed_area
.width
)
814 geom
.width
= allowed_area
.width
;
816 c
->ignore_strut
= false;
817 client_resize(c
, geom
, false);
821 /* WINDOW_TYPE_DOCK: left + right. */
822 foreach(_c
, globalconf
.clients
)
825 if(c
->screen
!= screen
|| !client_hasstrut(c
) || c
->type
!= WINDOW_TYPE_DOCK
)
828 /* Screen area, minus padding, wibox'es and already processed struts. */
829 allowed_area
= screen_area_get(c
->screen
,
836 if(c
->strut
.left
|| c
->strut
.left_start_y
|| c
->strut
.left_end_y
)
838 geom
.x
= allowed_area
.x
;
839 if(geom
.y
< allowed_area
.y
840 || geom
.y
+ geom
.height
> allowed_area
.y
+ allowed_area
.height
)
842 geom
.y
= allowed_area
.y
;
843 if (geom
.height
> allowed_area
.height
)
844 geom
.height
= allowed_area
.height
;
846 c
->ignore_strut
= false;
847 client_resize(c
, geom
, false);
849 else if(c
->strut
.right
|| c
->strut
.right_start_y
|| c
->strut
.right_end_y
)
851 geom
.x
= allowed_area
.x
+ allowed_area
.width
- geom
.width
;
852 if(geom
.y
< allowed_area
.y
853 || geom
.y
+ geom
.height
> allowed_area
.y
+ allowed_area
.height
)
855 geom
.y
= allowed_area
.y
;
856 if (geom
.height
> allowed_area
.height
)
857 geom
.height
= allowed_area
.height
;
859 c
->ignore_strut
= false;
860 client_resize(c
, geom
, false);
864 /* not WINDOW_TYPE_DOCK: top + bottom. */
865 foreach(_c
, globalconf
.clients
)
868 if(c
->screen
!= screen
|| !client_hasstrut(c
) || c
->type
== WINDOW_TYPE_DOCK
)
871 /* Screen area, minus padding, wibox'es and already processed struts. */
872 allowed_area
= screen_area_get(c
->screen
,
879 if(c
->strut
.top
|| c
->strut
.top_start_x
|| c
->strut
.top_end_x
)
881 geom
.y
= allowed_area
.y
;
882 if(geom
.x
< allowed_area
.x
883 || geom
.x
+ geom
.width
> allowed_area
.x
+ allowed_area
.width
)
885 geom
.x
= allowed_area
.x
;
886 if(geom
.width
> allowed_area
.width
)
887 geom
.width
= allowed_area
.width
;
889 c
->ignore_strut
= false;
890 client_resize(c
, geom
, false);
892 else if(c
->strut
.bottom
|| c
->strut
.bottom_start_x
|| c
->strut
.bottom_end_x
)
894 geom
.y
= allowed_area
.y
+ allowed_area
.height
- geom
.height
;
895 if(geom
.x
< allowed_area
.x
896 || geom
.x
+ geom
.width
> allowed_area
.x
+ allowed_area
.width
)
898 geom
.x
= allowed_area
.x
;
899 if(geom
.width
> allowed_area
.width
)
900 geom
.width
= allowed_area
.width
;
902 c
->ignore_strut
= false;
903 client_resize(c
, geom
, false);
907 /* not WINDOW_TYPE_DOCK: left + right. */
908 foreach(_c
, globalconf
.clients
)
911 if(c
->screen
!= screen
|| !client_hasstrut(c
) || c
->type
== WINDOW_TYPE_DOCK
)
914 /* Screen area, minus padding, wibox'es and already processed struts. */
915 allowed_area
= screen_area_get(c
->screen
,
922 if(c
->strut
.left
|| c
->strut
.left_start_y
|| c
->strut
.left_end_y
)
924 geom
.x
= allowed_area
.x
;
925 if(geom
.y
< allowed_area
.y
926 || geom
.y
+ geom
.height
> allowed_area
.y
+ allowed_area
.height
)
928 geom
.y
= allowed_area
.y
;
929 if (geom
.height
> allowed_area
.height
)
930 geom
.height
= allowed_area
.height
;
932 c
->ignore_strut
= false;
933 client_resize(c
, geom
, false);
935 else if(c
->strut
.right
|| c
->strut
.right_start_y
|| c
->strut
.right_end_y
)
937 geom
.x
= allowed_area
.x
+ allowed_area
.width
- geom
.width
;
938 if(geom
.y
< allowed_area
.y
939 || geom
.y
+ geom
.height
> allowed_area
.y
+ allowed_area
.height
)
941 geom
.y
= allowed_area
.y
;
942 if (geom
.height
> allowed_area
.height
)
943 geom
.height
= allowed_area
.height
;
945 c
->ignore_strut
= false;
946 client_resize(c
, geom
, false);
952 /** Set a client minimized, or not.
953 * \param c The client.
954 * \param s Set or not the client minimized.
957 client_setminimized(client_t
*c
, bool s
)
959 if(c
->isminimized
!= s
)
961 client_need_arrange(c
);
963 client_need_arrange(c
);
964 ewmh_client_update_hints(c
);
966 hooks_property(c
, "minimized");
970 /** Set a client sticky, or not.
971 * \param c The client.
972 * \param s Set or not the client sticky.
975 client_setsticky(client_t
*c
, bool s
)
979 client_need_arrange(c
);
981 client_need_arrange(c
);
982 ewmh_client_update_hints(c
);
983 hooks_property(c
, "sticky");
987 /** Set a client fullscreen, or not.
988 * \param c The client.
989 * \param s Set or not the client fullscreen.
992 client_setfullscreen(client_t
*c
, bool s
)
994 if(c
->isfullscreen
!= s
)
998 /* Make sure the current geometry is stored without titlebar. */
1000 titlebar_ban(c
->titlebar
);
1002 /* become fullscreen! */
1003 if((c
->isfullscreen
= s
))
1005 /* remove any max state */
1006 client_setmaxhoriz(c
, false);
1007 client_setmaxvert(c
, false);
1008 /* You can only be part of one of the special layers. */
1009 client_setbelow(c
, false);
1010 client_setabove(c
, false);
1011 client_setontop(c
, false);
1013 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
1014 c
->geometries
.fullscreen
= c
->geometry
;
1015 c
->border_fs
= c
->border
;
1016 client_setborder(c
, 0);
1020 geometry
= c
->geometries
.fullscreen
;
1021 client_setborder(c
, c
->border_fs
);
1023 client_resize(c
, geometry
, false);
1024 client_need_arrange(c
);
1026 ewmh_client_update_hints(c
);
1027 hooks_property(c
, "fullscreen");
1031 /** Set a client horizontally maximized.
1032 * \param c The client.
1033 * \param s The maximized status.
1036 client_setmaxhoriz(client_t
*c
, bool s
)
1038 if(c
->ismaxhoriz
!= s
)
1042 if((c
->ismaxhoriz
= s
))
1044 /* remove fullscreen mode */
1045 client_setfullscreen(c
, false);
1047 geometry
= screen_area_get(c
->screen
,
1048 &c
->screen
->wiboxes
,
1049 &c
->screen
->padding
,
1051 geometry
.y
= c
->geometry
.y
;
1052 geometry
.height
= c
->geometry
.height
;
1053 c
->geometries
.max
.x
= c
->geometry
.x
;
1054 c
->geometries
.max
.width
= c
->geometry
.width
;
1058 geometry
= c
->geometry
;
1059 geometry
.x
= c
->geometries
.max
.x
;
1060 geometry
.width
= c
->geometries
.max
.width
;
1063 client_resize(c
, geometry
, c
->size_hints_honor
);
1064 client_need_arrange(c
);
1066 ewmh_client_update_hints(c
);
1067 hooks_property(c
, "maximized_horizontal");
1071 /** Set a client vertically maximized.
1072 * \param c The client.
1073 * \param s The maximized status.
1076 client_setmaxvert(client_t
*c
, bool s
)
1078 if(c
->ismaxvert
!= s
)
1082 if((c
->ismaxvert
= s
))
1084 /* remove fullscreen mode */
1085 client_setfullscreen(c
, false);
1087 geometry
= screen_area_get(c
->screen
,
1088 &c
->screen
->wiboxes
,
1089 &c
->screen
->padding
,
1091 geometry
.x
= c
->geometry
.x
;
1092 geometry
.width
= c
->geometry
.width
;
1093 c
->geometries
.max
.y
= c
->geometry
.y
;
1094 c
->geometries
.max
.height
= c
->geometry
.height
;
1098 geometry
= c
->geometry
;
1099 geometry
.y
= c
->geometries
.max
.y
;
1100 geometry
.height
= c
->geometries
.max
.height
;
1103 client_resize(c
, geometry
, c
->size_hints_honor
);
1104 client_need_arrange(c
);
1106 ewmh_client_update_hints(c
);
1107 hooks_property(c
, "maximized_vertical");
1111 /** Set a client above, or not.
1112 * \param c The client.
1113 * \param s Set or not the client above.
1116 client_setabove(client_t
*c
, bool s
)
1120 /* You can only be part of one of the special layers. */
1123 client_setbelow(c
, false);
1124 client_setontop(c
, false);
1125 client_setfullscreen(c
, false);
1129 ewmh_client_update_hints(c
);
1131 hooks_property(c
, "above");
1135 /** Set a client below, or not.
1136 * \param c The client.
1137 * \param s Set or not the client below.
1140 client_setbelow(client_t
*c
, bool s
)
1144 /* You can only be part of one of the special layers. */
1147 client_setabove(c
, false);
1148 client_setontop(c
, false);
1149 client_setfullscreen(c
, false);
1153 ewmh_client_update_hints(c
);
1155 hooks_property(c
, "below");
1159 /** Set a client modal, or not.
1160 * \param c The client.
1161 * \param s Set or not the client moda.
1164 client_setmodal(client_t
*c
, bool s
)
1170 ewmh_client_update_hints(c
);
1172 hooks_property(c
, "modal");
1176 /** Set a client ontop, or not.
1177 * \param c The client.
1178 * \param s Set or not the client moda.
1181 client_setontop(client_t
*c
, bool s
)
1185 /* You can only be part of one of the special layers. */
1188 client_setabove(c
, false);
1189 client_setbelow(c
, false);
1190 client_setfullscreen(c
, false);
1195 hooks_property(c
, "ontop");
1199 /** Unban a client and move it back into the viewport.
1200 * \param c The client.
1203 client_unban(client_t
*c
)
1207 /* Move the client back where it belongs. */
1208 uint32_t request
[] = { c
->geometries
.internal
.x
,
1209 c
->geometries
.internal
.y
,
1210 c
->geometries
.internal
.width
,
1211 c
->geometries
.internal
.height
};
1213 xcb_configure_window(globalconf
.connection
, c
->win
,
1215 | XCB_CONFIG_WINDOW_Y
1216 | XCB_CONFIG_WINDOW_WIDTH
1217 | XCB_CONFIG_WINDOW_HEIGHT
,
1220 c
->isbanned
= false;
1222 /* All the wiboxes (may) need to be repositioned. */
1223 if(client_hasstrut(c
))
1224 wibox_update_positions();
1228 /** Unmanage a client.
1229 * \param c The client.
1232 client_unmanage(client_t
*c
)
1234 tag_array_t
*tags
= &c
->screen
->tags
;
1236 /* Reset transient_for attributes of widows that maybe refering to us */
1237 foreach(_tc
, globalconf
.clients
)
1239 client_t
*tc
= *_tc
;
1240 if(tc
->transient_for
== c
)
1241 tc
->transient_for
= NULL
;
1244 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1245 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1247 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1250 /* remove client from global list and everywhere else */
1251 foreach(elem
, globalconf
.clients
)
1254 client_array_remove(&globalconf
.clients
, elem
);
1257 stack_client_remove(c
);
1258 for(int i
= 0; i
< tags
->len
; i
++)
1259 untag_client(c
, tags
->tab
[i
]);
1262 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1264 client_push(globalconf
.L
, c
);
1265 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1268 /* Call hook to notify list change */
1269 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1270 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1272 /* The server grab construct avoids race conditions. */
1273 xcb_grab_server(globalconf
.connection
);
1275 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1276 XCB_BUTTON_MASK_ANY
);
1277 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1279 xcb_flush(globalconf
.connection
);
1280 xcb_ungrab_server(globalconf
.connection
);
1282 titlebar_client_detach(c
);
1284 ewmh_update_net_client_list(c
->phys_screen
);
1286 /* All the wiboxes (may) need to be repositioned. */
1287 if(client_hasstrut(c
))
1288 wibox_update_positions();
1290 /* set client as invalid */
1293 client_unref(globalconf
.L
, c
);
1296 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1298 * \param c The client to kill.
1301 client_kill(client_t
*c
)
1303 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1305 xcb_client_message_event_t ev
;
1307 /* Initialize all of event's fields first */
1310 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1313 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1314 ev
.type
= WM_PROTOCOLS
;
1315 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1317 xcb_send_event(globalconf
.connection
, false, c
->win
,
1318 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1321 xcb_kill_client(globalconf
.connection
, c
->win
);
1324 /** Get all clients into a table.
1325 * \param L The Lua VM state.
1326 * \return The number of elements pushed on stack.
1328 * \lparam An optional screen nunmber.
1329 * \lreturn A table with all clients.
1332 luaA_client_get(lua_State
*L
)
1336 screen
= luaL_optnumber(L
, 1, 0) - 1;
1341 foreach(c
, globalconf
.clients
)
1344 lua_rawseti(L
, -2, i
++);
1348 luaA_checkscreen(screen
);
1349 foreach(c
, globalconf
.clients
)
1350 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1353 lua_rawseti(L
, -2, i
++);
1360 /** Check if a client is visible on its screen.
1361 * \param L The Lua VM state.
1362 * \return The number of elements pushed on stack.
1365 * \lreturn A boolean value, true if the client is visible, false otherwise.
1368 luaA_client_isvisible(lua_State
*L
)
1370 client_t
*c
= luaA_client_checkudata(L
, 1);
1371 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1375 /** Set client border width.
1376 * \param c The client.
1377 * \param width The border width.
1380 client_setborder(client_t
*c
, int width
)
1384 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1385 || c
->type
== WINDOW_TYPE_SPLASH
1386 || c
->type
== WINDOW_TYPE_DESKTOP
1387 || c
->isfullscreen
))
1390 if(width
== c
->border
|| width
< 0)
1393 /* Update geometry with the new border. */
1394 c
->geometry
.width
-= 2 * c
->border
;
1395 c
->geometry
.height
-= 2 * c
->border
;
1398 xcb_configure_window(globalconf
.connection
, c
->win
,
1399 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1401 c
->geometry
.width
+= 2 * c
->border
;
1402 c
->geometry
.height
+= 2 * c
->border
;
1403 /* Tiled clients will be resized by the layout functions. */
1404 client_need_arrange(c
);
1406 /* Changing border size also affects the size of the titlebar. */
1407 titlebar_update_geometry(c
);
1409 hooks_property(c
, "border_width");
1413 * \param L The Lua VM state.
1419 luaA_client_kill(lua_State
*L
)
1421 client_t
*c
= luaA_client_checkudata(L
, 1);
1426 /** Swap a client with another one.
1427 * \param L The Lua VM state.
1430 * \lparam A client to swap with.
1433 luaA_client_swap(lua_State
*L
)
1435 client_t
*c
= luaA_client_checkudata(L
, 1);
1436 client_t
*swap
= luaA_client_checkudata(L
, 2);
1440 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1441 foreach(item
, globalconf
.clients
)
1445 else if(*item
== swap
)
1447 if(ref_c
&& ref_swap
)
1454 client_need_arrange(c
);
1455 client_need_arrange(swap
);
1457 /* Call hook to notify list change */
1458 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1459 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1465 /** Access or set the client tags.
1466 * \param L The Lua VM state.
1467 * \return The number of elements pushed on stack.
1468 * \lparam A table with tags to set, or none to get the current tags table.
1469 * \return The clients tag.
1472 luaA_client_tags(lua_State
*L
)
1474 client_t
*c
= luaA_client_checkudata(L
, 1);
1475 tag_array_t
*tags
= &c
->screen
->tags
;
1478 if(lua_gettop(L
) == 2)
1480 luaA_checktable(L
, 2);
1481 for(int i
= 0; i
< tags
->len
; i
++)
1482 untag_client(c
, tags
->tab
[i
]);
1484 while(lua_next(L
, 2))
1491 if(is_client_tagged(c
, *tag
))
1494 lua_rawseti(L
, -2, ++j
);
1500 /** Raise a client on top of others which are on the same layer.
1501 * \param L The Lua VM state.
1506 luaA_client_raise(lua_State
*L
)
1508 client_t
*c
= luaA_client_checkudata(L
, 1);
1513 /** Lower a client on bottom of others which are on the same layer.
1514 * \param L The Lua VM state.
1519 luaA_client_lower(lua_State
*L
)
1521 client_t
*c
= luaA_client_checkudata(L
, 1);
1526 /** Redraw a client by unmapping and mapping it quickly.
1527 * \param L The Lua VM state.
1533 luaA_client_redraw(lua_State
*L
)
1535 client_t
*c
= luaA_client_checkudata(L
, 1);
1537 xcb_unmap_window(globalconf
.connection
, c
->win
);
1538 xcb_map_window(globalconf
.connection
, c
->win
);
1540 /* Set the focus on the current window if the redraw has been
1541 performed on the window where the pointer is currently on
1542 because after the unmapping/mapping, the focus is lost */
1543 if(globalconf
.screen_focus
->client_focus
== c
)
1552 /** Stop managing a client.
1553 * \param L The Lua VM state.
1554 * \return The number of elements pushed on stack.
1559 luaA_client_unmanage(lua_State
*L
)
1561 client_t
*c
= luaA_client_checkudata(L
, 1);
1566 /** Return client geometry.
1567 * \param L The Lua VM state.
1568 * \return The number of elements pushed on stack.
1570 * \lparam A table with new coordinates, or none.
1571 * \lreturn A table with client coordinates.
1574 luaA_client_geometry(lua_State
*L
)
1576 client_t
*c
= luaA_client_checkudata(L
, 1);
1578 if(lua_gettop(L
) == 2)
1582 luaA_checktable(L
, 2);
1583 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1584 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1585 if(client_isfixed(c
))
1587 geometry
.width
= c
->geometry
.width
;
1588 geometry
.height
= c
->geometry
.height
;
1592 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1593 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1596 client_resize(c
, geometry
, c
->size_hints_honor
);
1599 return luaA_pusharea(L
, c
->geometry
);
1602 /** Push a strut type to a table on stack.
1603 * \param L The Lua VM state.
1604 * \param struts The struts to push.
1605 * \return The number of elements pushed on stack.
1608 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1610 lua_createtable(L
, 4, 0);
1611 lua_pushnumber(L
, struts
.left
);
1612 lua_setfield(L
, -2, "left");
1613 lua_pushnumber(L
, struts
.right
);
1614 lua_setfield(L
, -2, "right");
1615 lua_pushnumber(L
, struts
.top
);
1616 lua_setfield(L
, -2, "top");
1617 lua_pushnumber(L
, struts
.bottom
);
1618 lua_setfield(L
, -2, "bottom");
1622 /** Return client struts (reserved space at the edge of the screen).
1623 * \param L The Lua VM state.
1624 * \return The number of elements pushed on stack.
1626 * \lparam A table with new strut values, or none.
1627 * \lreturn A table with strut values.
1630 luaA_client_struts(lua_State
*L
)
1632 client_t
*c
= luaA_client_checkudata(L
, 1);
1634 if(lua_gettop(L
) == 2)
1637 area_t screen_area
= display_area_get(c
->phys_screen
, NULL
, NULL
);
1639 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1640 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1641 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1642 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1644 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1645 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1646 /* Struts are not so well defined in the context of xinerama. So we just
1647 * give the entire root window and let the window manager decide. */
1648 struts
.left_start_y
= 0;
1649 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1650 struts
.right_start_y
= 0;
1651 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1652 struts
.top_start_x
= 0;
1653 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1654 struts
.bottom_start_x
= 0;
1655 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1659 ewmh_update_client_strut(c
);
1661 client_need_arrange(c
);
1662 /* All the wiboxes (may) need to be repositioned. */
1663 wibox_update_positions();
1665 hooks_property(c
, "struts");
1669 return luaA_pushstruts(L
, c
->strut
);
1672 /** Client newindex.
1673 * \param L The Lua VM state.
1674 * \return The number of elements pushed on stack.
1677 luaA_client_newindex(lua_State
*L
)
1680 client_t
*c
= luaA_client_checkudata(L
, 1);
1681 const char *buf
= luaL_checklstring(L
, 2, &len
);
1686 switch(a_tokenize(buf
, len
))
1689 if(globalconf
.xinerama_is_active
)
1691 i
= luaL_checknumber(L
, 3) - 1;
1692 luaA_checkscreen(i
);
1693 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1697 b
= luaA_checkboolean(L
, 3);
1698 if(b
!= c
->ishidden
)
1700 client_need_arrange(c
);
1702 client_need_arrange(c
);
1705 case A_TK_MINIMIZED
:
1706 client_setminimized(c
, luaA_checkboolean(L
, 3));
1708 case A_TK_FULLSCREEN
:
1709 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1711 case A_TK_MAXIMIZED_HORIZONTAL
:
1712 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1714 case A_TK_MAXIMIZED_VERTICAL
:
1715 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1718 image_unref(L
, c
->icon
);
1719 c
->icon
= image_ref(L
);
1721 hooks_property(c
, "icon");
1725 window_opacity_set(c
->win
, -1);
1728 d
= luaL_checknumber(L
, 3);
1729 if(d
>= 0 && d
<= 1)
1730 window_opacity_set(c
->win
, d
);
1734 client_setsticky(c
, luaA_checkboolean(L
, 3));
1736 case A_TK_SIZE_HINTS_HONOR
:
1737 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1738 hooks_property(c
, "size_hints_honor");
1740 case A_TK_BORDER_WIDTH
:
1741 client_setborder(c
, luaL_checknumber(L
, 3));
1744 client_setontop(c
, luaA_checkboolean(L
, 3));
1747 client_setabove(c
, luaA_checkboolean(L
, 3));
1750 client_setbelow(c
, luaA_checkboolean(L
, 3));
1753 client_seturgent(c
, luaA_checkboolean(L
, 3));
1755 case A_TK_BORDER_COLOR
:
1756 if((buf
= luaL_checklstring(L
, 3, &len
))
1757 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1758 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1759 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1763 titlebar_client_detach(c
);
1765 titlebar_client_attach(c
);
1775 * \param L The Lua VM state.
1776 * \return The number of elements pushed on stack.
1778 * \lfield id The window X id.
1779 * \lfield name The client title.
1780 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1781 * \lfield type The window type (desktop, normal, dock, …).
1782 * \lfield class The client class.
1783 * \lfield instance The client instance.
1784 * \lfield pid The client PID, if available.
1785 * \lfield role The window role, if available.
1786 * \lfield machine The machine client is running on.
1787 * \lfield icon_name The client name when iconified.
1788 * \lfield screen Client screen number.
1789 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1790 * invisible in taskbar.
1791 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1793 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1794 * \lfield border_width The client border width.
1795 * \lfield border_color The client border color.
1796 * \lfield titlebar The client titlebar.
1797 * \lfield urgent The client urgent state.
1798 * \lfield content An image representing the client window content (screenshot).
1799 * \lfield focus The focused client.
1800 * \lfield opacity The client opacity between 0 and 1.
1801 * \lfield ontop The client is on top of every other windows.
1802 * \lfield above The client is above normal windows.
1803 * \lfield below The client is below normal windows.
1804 * \lfield fullscreen The client is fullscreen or not.
1805 * \lfield maximized_horizontal The client is maximized horizontally or not.
1806 * \lfield maximized_vertical The client is maximized vertically or not.
1807 * \lfield transient_for Return the client the window is transient for.
1808 * \lfield group_id Identification unique to a group of windows.
1809 * \lfield leader_id Identification unique to windows spawned by the same command.
1810 * \lfield size_hints A table with size hints of the client: user_position,
1811 * user_size, program_position, program_size, etc.
1814 luaA_client_index(lua_State
*L
)
1818 client_t
*c
= luaA_client_checkudata(L
, 1);
1819 const char *buf
= luaL_checklstring(L
, 2, &len
);
1822 xcb_get_property_cookie_t prop_c
;
1823 xcb_get_property_reply_t
*prop_r
= NULL
;
1826 if(luaA_usemetatable(L
, 1, 2))
1829 switch(a_tokenize(buf
, len
))
1832 lua_pushstring(L
, c
->name
);
1834 case A_TK_TRANSIENT_FOR
:
1835 return client_push(globalconf
.L
, c
->transient_for
);
1836 case A_TK_SKIP_TASKBAR
:
1837 lua_pushboolean(L
, c
->skiptb
);
1840 return client_getcontent(c
);
1844 case WINDOW_TYPE_DESKTOP
:
1845 lua_pushliteral(L
, "desktop");
1847 case WINDOW_TYPE_DOCK
:
1848 lua_pushliteral(L
, "dock");
1850 case WINDOW_TYPE_SPLASH
:
1851 lua_pushliteral(L
, "splash");
1853 case WINDOW_TYPE_DIALOG
:
1854 lua_pushliteral(L
, "dialog");
1856 case WINDOW_TYPE_MENU
:
1857 lua_pushliteral(L
, "menu");
1859 case WINDOW_TYPE_TOOLBAR
:
1860 lua_pushliteral(L
, "toolbar");
1862 case WINDOW_TYPE_UTILITY
:
1863 lua_pushliteral(L
, "utility");
1865 case WINDOW_TYPE_DROPDOWN_MENU
:
1866 lua_pushliteral(L
, "dropdown_menu");
1868 case WINDOW_TYPE_POPUP_MENU
:
1869 lua_pushliteral(L
, "popup_menu");
1871 case WINDOW_TYPE_TOOLTIP
:
1872 lua_pushliteral(L
, "tooltip");
1874 case WINDOW_TYPE_NOTIFICATION
:
1875 lua_pushliteral(L
, "notification");
1877 case WINDOW_TYPE_COMBO
:
1878 lua_pushliteral(L
, "combo");
1880 case WINDOW_TYPE_DND
:
1881 lua_pushliteral(L
, "dnd");
1883 case WINDOW_TYPE_NORMAL
:
1884 lua_pushliteral(L
, "normal");
1889 lua_pushstring(L
, c
->class);
1892 lua_pushstring(L
, c
->instance
);
1895 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1896 WM_WINDOW_ROLE
, &value
, &slen
))
1898 lua_pushlstring(L
, value
, slen
);
1902 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1903 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1905 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1906 lua_pushnumber(L
, *(uint32_t *)data
);
1914 lua_pushnumber(L
, c
->win
);
1916 case A_TK_LEADER_ID
:
1917 lua_pushnumber(L
, c
->leader_win
);
1920 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1921 WM_CLIENT_MACHINE
, &value
, &slen
))
1923 lua_pushlstring(L
, value
, slen
);
1926 case A_TK_ICON_NAME
:
1927 lua_pushstring(L
, c
->icon_name
);
1930 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1933 lua_pushboolean(L
, c
->ishidden
);
1935 case A_TK_MINIMIZED
:
1936 lua_pushboolean(L
, c
->isminimized
);
1938 case A_TK_FULLSCREEN
:
1939 lua_pushboolean(L
, c
->isfullscreen
);
1943 lua_pushnumber(L
, c
->group_win
);
1947 case A_TK_MAXIMIZED_HORIZONTAL
:
1948 lua_pushboolean(L
, c
->ismaxhoriz
);
1950 case A_TK_MAXIMIZED_VERTICAL
:
1951 lua_pushboolean(L
, c
->ismaxvert
);
1954 image_push(L
, c
->icon
);
1957 if((d
= window_opacity_get(c
->win
)) >= 0)
1958 lua_pushnumber(L
, d
);
1963 lua_pushboolean(L
, c
->isontop
);
1966 lua_pushboolean(L
, c
->isabove
);
1969 lua_pushboolean(L
, c
->isbelow
);
1972 lua_pushboolean(L
, c
->issticky
);
1974 case A_TK_SIZE_HINTS_HONOR
:
1975 lua_pushboolean(L
, c
->size_hints_honor
);
1977 case A_TK_BORDER_WIDTH
:
1978 lua_pushnumber(L
, c
->border
);
1980 case A_TK_BORDER_COLOR
:
1981 luaA_pushxcolor(L
, &c
->border_color
);
1984 return wibox_push(L
, c
->titlebar
);
1986 lua_pushboolean(L
, c
->isurgent
);
1988 case A_TK_SIZE_HINTS
:
1990 const char *u_or_p
= NULL
;
1992 lua_createtable(L
, 0, 1);
1994 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1995 u_or_p
= "user_position";
1996 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1997 u_or_p
= "program_position";
2001 lua_createtable(L
, 0, 2);
2002 lua_pushnumber(L
, c
->size_hints
.x
);
2003 lua_setfield(L
, -2, "x");
2004 lua_pushnumber(L
, c
->size_hints
.y
);
2005 lua_setfield(L
, -2, "y");
2006 lua_setfield(L
, -2, u_or_p
);
2010 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
2011 u_or_p
= "user_size";
2012 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
2013 u_or_p
= "program_size";
2017 lua_createtable(L
, 0, 2);
2018 lua_pushnumber(L
, c
->size_hints
.width
);
2019 lua_setfield(L
, -2, "width");
2020 lua_pushnumber(L
, c
->size_hints
.height
);
2021 lua_setfield(L
, -2, "height");
2022 lua_setfield(L
, -2, u_or_p
);
2025 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
2027 lua_pushnumber(L
, c
->size_hints
.min_width
);
2028 lua_setfield(L
, -2, "min_width");
2029 lua_pushnumber(L
, c
->size_hints
.min_height
);
2030 lua_setfield(L
, -2, "min_height");
2033 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
2035 lua_pushnumber(L
, c
->size_hints
.max_width
);
2036 lua_setfield(L
, -2, "max_width");
2037 lua_pushnumber(L
, c
->size_hints
.max_height
);
2038 lua_setfield(L
, -2, "max_height");
2041 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
2043 lua_pushnumber(L
, c
->size_hints
.width_inc
);
2044 lua_setfield(L
, -2, "width_inc");
2045 lua_pushnumber(L
, c
->size_hints
.height_inc
);
2046 lua_setfield(L
, -2, "height_inc");
2049 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
2051 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
2052 lua_setfield(L
, -2, "min_aspect_num");
2053 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
2054 lua_setfield(L
, -2, "min_aspect_den");
2055 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
2056 lua_setfield(L
, -2, "max_aspect_num");
2057 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
2058 lua_setfield(L
, -2, "max_aspect_den");
2061 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
2063 lua_pushnumber(L
, c
->size_hints
.base_width
);
2064 lua_setfield(L
, -2, "base_width");
2065 lua_pushnumber(L
, c
->size_hints
.base_height
);
2066 lua_setfield(L
, -2, "base_height");
2069 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
2071 switch(c
->size_hints
.win_gravity
)
2074 lua_pushliteral(L
, "north_west");
2076 case XCB_GRAVITY_NORTH
:
2077 lua_pushliteral(L
, "north");
2079 case XCB_GRAVITY_NORTH_EAST
:
2080 lua_pushliteral(L
, "north_east");
2082 case XCB_GRAVITY_WEST
:
2083 lua_pushliteral(L
, "west");
2085 case XCB_GRAVITY_CENTER
:
2086 lua_pushliteral(L
, "center");
2088 case XCB_GRAVITY_EAST
:
2089 lua_pushliteral(L
, "east");
2091 case XCB_GRAVITY_SOUTH_WEST
:
2092 lua_pushliteral(L
, "south_west");
2094 case XCB_GRAVITY_SOUTH
:
2095 lua_pushliteral(L
, "south");
2097 case XCB_GRAVITY_SOUTH_EAST
:
2098 lua_pushliteral(L
, "south_east");
2100 case XCB_GRAVITY_STATIC
:
2101 lua_pushliteral(L
, "static");
2104 lua_setfield(L
, -2, "win_gravity");
2115 /** Get or set mouse buttons bindings for a client.
2116 * \param L The Lua VM state.
2117 * \return The number of element pushed on stack.
2120 * \lparam An array of mouse button bindings objects, or nothing.
2121 * \return The array of mouse button bindings objects of this client.
2124 luaA_client_buttons(lua_State
*L
)
2126 client_t
*client
= luaA_client_checkudata(L
, 1);
2127 button_array_t
*buttons
= &client
->buttons
;
2129 if(lua_gettop(L
) == 2)
2130 luaA_button_array_set(L
, 2, buttons
);
2132 window_buttons_grab(client
->win
, &client
->buttons
);
2134 return luaA_button_array_get(L
, buttons
);
2137 /** Get or set keys bindings for a client.
2138 * \param L The Lua VM state.
2139 * \return The number of element pushed on stack.
2142 * \lparam An array of key bindings objects, or nothing.
2143 * \return The array of key bindings objects of this client.
2146 luaA_client_keys(lua_State
*L
)
2148 client_t
*c
= luaA_client_checkudata(L
, 1);
2149 key_array_t
*keys
= &c
->keys
;
2151 if(lua_gettop(L
) == 2)
2153 luaA_key_array_set(L
, 2, keys
);
2154 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
2155 window_grabkeys(c
->win
, keys
);
2158 return luaA_key_array_get(L
, keys
);
2162 * \param L The Lua VM state.
2163 * \return The number of pushed elements.
2166 luaA_client_module_index(lua_State
*L
)
2169 const char *buf
= luaL_checklstring(L
, 2, &len
);
2171 switch(a_tokenize(buf
, len
))
2174 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
2181 /* Client module new index.
2182 * \param L The Lua VM state.
2183 * \return The number of pushed elements.
2186 luaA_client_module_newindex(lua_State
*L
)
2189 const char *buf
= luaL_checklstring(L
, 2, &len
);
2192 switch(a_tokenize(buf
, len
))
2195 c
= luaA_client_checkudata(L
, 3);
2205 const struct luaL_reg awesome_client_methods
[] =
2207 { "get", luaA_client_get
},
2208 { "__index", luaA_client_module_index
},
2209 { "__newindex", luaA_client_module_newindex
},
2212 const struct luaL_reg awesome_client_meta
[] =
2214 { "isvisible", luaA_client_isvisible
},
2215 { "geometry", luaA_client_geometry
},
2216 { "struts", luaA_client_struts
},
2217 { "buttons", luaA_client_buttons
},
2218 { "keys", luaA_client_keys
},
2219 { "tags", luaA_client_tags
},
2220 { "kill", luaA_client_kill
},
2221 { "swap", luaA_client_swap
},
2222 { "raise", luaA_client_raise
},
2223 { "lower", luaA_client_lower
},
2224 { "redraw", luaA_client_redraw
},
2225 { "unmanage", luaA_client_unmanage
},
2226 { "__index", luaA_client_index
},
2227 { "__newindex", luaA_client_newindex
},
2228 { "__gc", luaA_client_gc
},
2229 { "__tostring", luaA_client_tostring
},
2233 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80