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>
33 #include "common/atoms.h"
34 #include "common/xutil.h"
37 luaA_client_checkudata(lua_State
*L
, int ud
)
39 client_t
*c
= luaA_checkudata(L
, ud
, &client_class
);
41 luaL_error(L
, "client is invalid\n");
46 * \param L The Lua VM state.
47 * \return The number of element pushed on stack.
50 luaA_client_gc(lua_State
*L
)
52 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
53 button_array_wipe(&c
->buttons
);
54 key_array_wipe(&c
->keys
);
55 xcb_get_wm_protocols_reply_wipe(&c
->protocols
);
57 p_delete(&c
->instance
);
58 p_delete(&c
->icon_name
);
59 p_delete(&c
->alt_icon_name
);
61 p_delete(&c
->alt_name
);
62 return luaA_object_gc(L
);
65 /** Change the client opacity.
66 * \param L The Lua VM state.
67 * \param cidx The client index.
68 * \param opacity The opacity.
71 client_set_opacity(lua_State
*L
, int cidx
, double opacity
)
73 client_t
*c
= luaA_client_checkudata(L
, cidx
);
75 if(c
->opacity
!= opacity
)
78 window_opacity_set(c
->window
, opacity
);
79 luaA_object_emit_signal(L
, cidx
, "property::opacity", 0);
83 /** Change the clients urgency flag.
84 * \param L The Lua VM state.
85 * \param cidx The client index on the stack.
86 * \param urgent The new flag state.
89 client_set_urgent(lua_State
*L
, int cidx
, bool urgent
)
91 client_t
*c
= luaA_client_checkudata(L
, cidx
);
93 if(c
->urgent
!= urgent
)
95 xcb_get_property_cookie_t hints
=
96 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->window
);
99 ewmh_client_update_hints(c
);
101 /* update ICCCM hints */
103 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
106 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
108 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
110 xcb_set_wm_hints(globalconf
.connection
, c
->window
, &wmh
);
112 hook_property(c
, "urgent");
113 luaA_object_emit_signal(L
, cidx
, "property::urgent", 0);
118 client_set_group_window(lua_State
*L
, int cidx
, xcb_window_t window
)
120 client_t
*c
= luaA_client_checkudata(L
, cidx
);
122 if(c
->group_window
!= window
)
124 c
->group_window
= window
;
125 luaA_object_emit_signal(L
, cidx
, "property::group_window", 0);
130 client_set_type(lua_State
*L
, int cidx
, window_type_t type
)
132 client_t
*c
= luaA_client_checkudata(L
, cidx
);
137 luaA_object_emit_signal(L
, cidx
, "property::type", 0);
142 client_set_pid(lua_State
*L
, int cidx
, uint32_t pid
)
144 client_t
*c
= luaA_client_checkudata(L
, cidx
);
149 luaA_object_emit_signal(L
, cidx
, "property::pid", 0);
154 client_set_icon_name(lua_State
*L
, int cidx
, char *icon_name
)
156 client_t
*c
= luaA_client_checkudata(L
, cidx
);
157 p_delete(&c
->icon_name
);
158 c
->icon_name
= icon_name
;
159 luaA_object_emit_signal(L
, cidx
, "property::icon_name", 0);
160 hook_property(c
, "icon_name");
164 client_set_alt_icon_name(lua_State
*L
, int cidx
, char *icon_name
)
166 client_t
*c
= luaA_client_checkudata(L
, cidx
);
167 p_delete(&c
->alt_icon_name
);
168 c
->alt_icon_name
= icon_name
;
169 luaA_object_emit_signal(L
, cidx
, "property::icon_name", 0);
170 hook_property(c
, "icon_name");
174 client_set_role(lua_State
*L
, int cidx
, char *role
)
176 client_t
*c
= luaA_client_checkudata(L
, cidx
);
179 luaA_object_emit_signal(L
, cidx
, "property::role", 0);
183 client_set_machine(lua_State
*L
, int cidx
, char *machine
)
185 client_t
*c
= luaA_client_checkudata(L
, cidx
);
186 p_delete(&c
->machine
);
187 c
->machine
= machine
;
188 luaA_object_emit_signal(L
, cidx
, "property::machine", 0);
192 client_set_class_instance(lua_State
*L
, int cidx
, const char *class, const char *instance
)
194 client_t
*c
= luaA_client_checkudata(L
, cidx
);
196 p_delete(&c
->instance
);
197 c
->class = a_strdup(class);
198 c
->instance
= a_strdup(instance
);
199 luaA_object_emit_signal(L
, cidx
, "property::class", 0);
200 luaA_object_emit_signal(L
, cidx
, "property::instance", 0);
204 client_set_transient_for(lua_State
*L
, int cidx
, client_t
*transient_for
)
206 client_t
*c
= luaA_client_checkudata(L
, cidx
);
208 if(c
->transient_for
!= transient_for
)
210 c
->transient_for
= transient_for
;
211 luaA_object_emit_signal(L
, cidx
, "property::transient_for", 0);
216 client_set_name(lua_State
*L
, int cidx
, char *name
)
218 client_t
*c
= luaA_client_checkudata(L
, cidx
);
221 hook_property(c
, "name");
222 luaA_object_emit_signal(L
, cidx
, "property::name", 0);
226 client_set_alt_name(lua_State
*L
, int cidx
, char *name
)
228 client_t
*c
= luaA_client_checkudata(L
, cidx
);
229 p_delete(&c
->alt_name
);
231 hook_property(c
, "name");
232 luaA_object_emit_signal(L
, cidx
, "property::name", 0);
235 /** Returns true if a client is tagged
236 * with one of the tags of the specified screen.
237 * \param c The client to check.
238 * \param screen Virtual screen.
239 * \return true if the client is visible, false otherwise.
242 client_maybevisible(client_t
*c
, screen_t
*screen
)
244 if(screen
&& c
->screen
== screen
)
246 if(c
->sticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
249 foreach(tag
, screen
->tags
)
250 if(tag_get_selected(*tag
) && is_client_tagged(c
, *tag
))
256 /** Get a client by its window.
257 * \param w The client window to find.
258 * \return A client pointer if found, NULL otherwise.
261 client_getbywin(xcb_window_t w
)
263 foreach(c
, globalconf
.clients
)
264 if((*c
)->window
== w
)
270 /** Record that a client lost focus.
271 * \param c Client being unfocused
274 client_unfocus_update(client_t
*c
)
276 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
277 ewmh_update_net_active_window(c
->phys_screen
);
280 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
282 luaA_object_push(globalconf
.L
, c
);
283 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
286 luaA_object_push(globalconf
.L
, c
);
287 luaA_class_emit_signal(globalconf
.L
, &client_class
, "unfocus", 1);
290 /** Unfocus a client.
291 * \param c The client.
294 client_unfocus(client_t
*c
)
297 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
298 /* Set focus on root window, so no events leak to the current window.
299 * This kind of inlines client_set_focus(), but a root window will never have
300 * the WM_TAKE_FOCUS protocol.
302 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
303 root_win
, XCB_CURRENT_TIME
);
305 client_unfocus_update(c
);
308 /** Check if client supports protocol a protocole in WM_PROTOCOL.
309 * \param c The client.
310 * \param atom The protocol atom to check for.
311 * \return True if client has the atom in protocol, false otherwise.
314 client_hasproto(client_t
*c
, xcb_atom_t atom
)
316 for(uint32_t i
= 0; i
< c
->protocols
.atoms_len
; i
++)
317 if(c
->protocols
.atoms
[i
] == atom
)
322 /** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS
323 * \param c Client that should get focus
324 * \param set_input_focus Should we call xcb_set_input_focus
327 client_set_focus(client_t
*c
, bool set_input_focus
)
329 bool takefocus
= client_hasproto(c
, WM_TAKE_FOCUS
);
331 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
332 c
->window
, XCB_CURRENT_TIME
);
334 window_takefocus(c
->window
);
337 /** Ban client and move it out of the viewport.
338 * \param c The client.
341 client_ban(client_t
*c
)
345 xcb_unmap_window(globalconf
.connection
, c
->window
);
349 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
350 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
352 /* Wait until the last moment to take away the focus from the window. */
353 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
358 /** This is part of The Bob Marley Algorithmm: we ignore enter and leave window
359 * in certain cases, like map/unmap or move, so we don't get spurious events.
362 client_ignore_enterleave_events(void)
364 foreach(c
, globalconf
.clients
)
365 xcb_change_window_attributes(globalconf
.connection
,
368 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
& ~(XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
) });
372 client_restore_enterleave_events(void)
374 foreach(c
, globalconf
.clients
)
375 xcb_change_window_attributes(globalconf
.connection
,
378 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
});
381 /** Record that a client got focus.
382 * \param c The client.
385 client_focus_update(client_t
*c
)
387 if(!client_maybevisible(c
, c
->screen
))
389 /* Focus previously focused client */
390 client_focus(globalconf
.screen_focus
->prev_client_focus
);
394 if(globalconf
.screen_focus
395 && globalconf
.screen_focus
->client_focus
)
397 if (globalconf
.screen_focus
->client_focus
!= c
)
398 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
400 /* Already focused */
403 luaA_object_push(globalconf
.L
, c
);
404 client_set_minimized(globalconf
.L
, -1, false);
406 /* unban the client before focusing for consistency */
409 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
410 globalconf
.screen_focus
->prev_client_focus
= c
;
411 globalconf
.screen_focus
->client_focus
= c
;
413 /* according to EWMH, we have to remove the urgent state from a client */
414 client_set_urgent(globalconf
.L
, -1, false);
416 ewmh_update_net_active_window(c
->phys_screen
);
419 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
421 luaA_object_push(globalconf
.L
, c
);
422 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
425 luaA_object_push(globalconf
.L
, c
);
426 luaA_class_emit_signal(globalconf
.L
, &client_class
, "focus", 1);
429 /** Give focus to client, or to first client if client is NULL.
430 * \param c The client.
433 client_focus(client_t
*c
)
435 /* We have to set focus on first client */
436 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
439 if(!client_maybevisible(c
, c
->screen
))
443 client_focus_update(c
);
445 client_set_focus(c
, !c
->nofocus
);
448 /** Stack a window below.
449 * \param c The client.
450 * \param previous The previous window on the stack.
451 * \return The next-previous!
454 client_stack_above(client_t
*c
, xcb_window_t previous
)
456 uint32_t config_win_vals
[2];
458 config_win_vals
[0] = previous
;
459 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
461 xcb_configure_window(globalconf
.connection
, c
->window
,
462 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
465 config_win_vals
[0] = c
->window
;
469 xcb_configure_window(globalconf
.connection
,
471 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
473 previous
= c
->titlebar
->window
;
476 previous
= c
->window
;
478 /* stack transient window on top of their parents */
479 foreach(node
, globalconf
.stack
)
480 if((*node
)->transient_for
== c
)
481 previous
= client_stack_above(*node
, previous
);
486 /** Stacking layout layers */
489 /** This one is a special layer */
497 /** This one only used for counting and is not a real layer */
501 /** Get the real layer of a client according to its attribute (fullscreen, …)
502 * \param c The client.
503 * \return The real layer.
506 client_layer_translator(client_t
*c
)
508 /* first deal with user set attributes */
511 else if(c
->fullscreen
)
512 return LAYER_FULLSCREEN
;
518 /* check for transient attr */
522 /* then deal with windows type */
525 case WINDOW_TYPE_DESKTOP
:
526 return LAYER_DESKTOP
;
535 * \todo It might be worth stopping to restack everyone and only stack `c'
536 * relatively to the first matching in the list.
539 client_stack_refresh()
541 uint32_t config_win_vals
[2];
544 if (!globalconf
.client_need_stack_refresh
)
546 globalconf
.client_need_stack_refresh
= false;
548 config_win_vals
[0] = XCB_NONE
;
549 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
551 /* stack desktop windows */
552 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
553 foreach(node
, globalconf
.stack
)
554 if(client_layer_translator(*node
) == layer
)
555 config_win_vals
[0] = client_stack_above(*node
,
558 /* first stack not ontop wibox window */
559 foreach(_sb
, globalconf
.wiboxes
)
564 xcb_configure_window(globalconf
.connection
,
566 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
568 config_win_vals
[0] = sb
->window
;
572 /* then stack clients */
573 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
574 foreach(node
, globalconf
.stack
)
575 if(client_layer_translator(*node
) == layer
)
576 config_win_vals
[0] = client_stack_above(*node
,
579 /* then stack ontop wibox window */
580 foreach(_sb
, globalconf
.wiboxes
)
585 xcb_configure_window(globalconf
.connection
,
587 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
589 config_win_vals
[0] = sb
->window
;
594 /** Manage a new client.
595 * \param w The window.
596 * \param wgeom Window geometry.
597 * \param phys_screen Physical screen number.
598 * \param startup True if we are managing at startup time.
601 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
604 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
606 if(systray_iskdedockapp(w
))
608 systray_request_handle(w
, phys_screen
, NULL
);
612 /* If this is a new client that just has been launched, then request its
614 xcb_get_property_cookie_t startup_id_q
= { 0 };
616 startup_id_q
= xcb_get_any_property(globalconf
.connection
,
617 false, w
, _NET_STARTUP_ID
, UINT_MAX
);
619 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
621 client_t
*c
= client_new(globalconf
.L
);
622 /* Push client in client list */
623 client_array_push(&globalconf
.clients
, luaA_object_ref(globalconf
.L
, -1));
626 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
629 c
->phys_screen
= phys_screen
;
631 /* consider the window banned */
636 c
->geometry
.x
= wgeom
->x
;
637 c
->geometry
.y
= wgeom
->y
;
638 /* Border will be added later. */
639 c
->geometry
.width
= wgeom
->width
;
640 c
->geometry
.height
= wgeom
->height
;
641 /* Also set internal geometry (client_ban() needs it). */
642 c
->geometries
.internal
.x
= wgeom
->x
;
643 c
->geometries
.internal
.y
= wgeom
->y
;
644 c
->geometries
.internal
.width
= wgeom
->width
;
645 c
->geometries
.internal
.height
= wgeom
->height
;
648 luaA_object_push(globalconf
.L
, c
);
649 client_set_border_width(globalconf
.L
, -1, wgeom
->border_width
);
650 lua_pop(globalconf
.L
, 1);
652 /* we honor size hints by default */
653 c
->size_hints_honor
= true;
656 property_update_wm_normal_hints(c
, NULL
);
657 property_update_wm_hints(c
, NULL
);
658 property_update_wm_transient_for(c
, NULL
);
659 property_update_wm_client_leader(c
, NULL
);
660 property_update_wm_client_machine(c
, NULL
);
661 property_update_wm_window_role(c
, NULL
);
662 property_update_net_wm_pid(c
, NULL
);
663 property_update_net_wm_icon(c
, NULL
);
666 c
->opacity
= window_opacity_get(c
->window
);
668 /* Then check clients hints */
669 ewmh_client_check_hints(c
);
671 screen_client_moveto(c
, screen
, true);
673 /* Push client in stack */
676 /* update window title */
677 property_update_wm_name(c
, NULL
);
678 property_update_net_wm_name(c
, NULL
);
679 property_update_wm_icon_name(c
, NULL
);
680 property_update_net_wm_icon_name(c
, NULL
);
681 property_update_wm_class(c
, NULL
);
682 property_update_wm_protocols(c
, NULL
);
685 ewmh_process_client_strut(c
, NULL
);
687 ewmh_update_net_client_list(c
->phys_screen
);
689 /* Always stay in NORMAL_STATE. Even though iconified seems more
690 * appropriate sometimes. The only possible loss is that clients not using
691 * visibility events may continue to proces data (when banned).
692 * Without any exposes or other events the cost should be fairly limited though.
694 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
695 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
697 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
698 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
700 * "Once a client's window has left the Withdrawn state, the window will be mapped
701 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
703 * At this stage it's just safer to keep it in normal state and avoid confusion.
705 window_state_set(c
->window
, XCB_WM_STATE_NORMAL
);
709 /* Request our response */
710 xcb_get_property_reply_t
*reply
=
711 xcb_get_property_reply(globalconf
.connection
, startup_id_q
, NULL
);
712 /* Say spawn that a client has been started, with startup id as argument */
713 char *startup_id
= xutil_get_text_property_from_reply(reply
);
715 spawn_start_notify(c
, startup_id
);
716 p_delete(&startup_id
);
719 /* Call hook to notify list change */
720 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
721 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
723 luaA_class_emit_signal(globalconf
.L
, &client_class
, "list", 0);
726 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
728 luaA_object_push(globalconf
.L
, c
);
729 lua_pushboolean(globalconf
.L
, startup
);
730 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
733 luaA_object_push(globalconf
.L
, c
);
734 lua_pushboolean(globalconf
.L
, startup
);
735 luaA_class_emit_signal(globalconf
.L
, &client_class
, "manage", 2);
738 /** Compute client geometry with respect to its geometry hints.
739 * \param c The client.
740 * \param geometry The geometry that the client might receive.
741 * \return The geometry the client must take respecting its hints.
744 client_geometry_hints(client_t
*c
, area_t geometry
)
746 int32_t basew
, baseh
, minw
, minh
;
748 /* base size is substituted with min size if not specified */
749 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
751 basew
= c
->size_hints
.base_width
;
752 baseh
= c
->size_hints
.base_height
;
754 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
756 basew
= c
->size_hints
.min_width
;
757 baseh
= c
->size_hints
.min_height
;
762 /* min size is substituted with base size if not specified */
763 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
765 minw
= c
->size_hints
.min_width
;
766 minh
= c
->size_hints
.min_height
;
768 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
770 minw
= c
->size_hints
.base_width
;
771 minh
= c
->size_hints
.base_height
;
776 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
777 && c
->size_hints
.min_aspect_num
> 0
778 && c
->size_hints
.min_aspect_den
> 0
779 && geometry
.height
- baseh
> 0
780 && geometry
.width
- basew
> 0)
782 double dx
= (double) (geometry
.width
- basew
);
783 double dy
= (double) (geometry
.height
- baseh
);
784 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
785 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
786 double ratio
= dx
/ dy
;
787 if(max
> 0 && min
> 0 && ratio
> 0)
791 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
793 geometry
.width
= (int) dx
+ basew
;
794 geometry
.height
= (int) dy
+ baseh
;
798 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
800 geometry
.width
= (int) dx
+ basew
;
801 geometry
.height
= (int) dy
+ baseh
;
807 geometry
.width
= MAX(geometry
.width
, minw
);
809 geometry
.height
= MAX(geometry
.height
, minh
);
811 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
813 if(c
->size_hints
.max_width
)
814 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
815 if(c
->size_hints
.max_height
)
816 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
819 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
820 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
822 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
823 unsigned_subtract(t1
, basew
);
824 unsigned_subtract(t2
, baseh
);
825 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
826 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
832 /** Resize client window.
833 * The sizse given as parameters are with titlebar and borders!
834 * \param c Client to resize.
835 * \param geometry New window geometry.
836 * \param hints Use size hints.
837 * \return true if an actual resize occurred.
840 client_resize(client_t
*c
, area_t geometry
, bool hints
)
842 area_t geometry_internal
;
845 /* offscreen appearance fixes */
846 area
= display_area_get(c
->phys_screen
);
848 if(geometry
.x
> area
.width
)
849 geometry
.x
= area
.width
- geometry
.width
;
850 if(geometry
.y
> area
.height
)
851 geometry
.y
= area
.height
- geometry
.height
;
852 if(geometry
.x
+ geometry
.width
< 0)
854 if(geometry
.y
+ geometry
.height
< 0)
857 /* Real client geometry, please keep it contained to C code at the very least. */
858 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border_width
, geometry
);
861 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
863 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
866 /* Also let client hints propegate to the "official" geometry. */
867 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border_width
, geometry_internal
);
869 if(c
->geometries
.internal
.x
!= geometry_internal
.x
870 || c
->geometries
.internal
.y
!= geometry_internal
.y
871 || c
->geometries
.internal
.width
!= geometry_internal
.width
872 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
874 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
875 geometry_internal
.x
, geometry_internal
.y
);
877 /* Values to configure a window is an array where values are
878 * stored according to 'value_mask' */
881 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
882 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
883 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
884 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
886 /* Also store geometry including border and titlebar. */
887 c
->geometry
= geometry
;
889 titlebar_update_geometry(c
);
891 /* Ignore all spurious enter/leave notify events */
892 client_ignore_enterleave_events();
894 xcb_configure_window(globalconf
.connection
, c
->window
,
895 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
896 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
899 client_restore_enterleave_events();
901 screen_client_moveto(c
, new_screen
, false);
904 hook_property(c
, "geometry");
912 /** Set a client minimized, or not.
913 * \param L The Lua VM state.
914 * \param cidx The client index.
915 * \param s Set or not the client minimized.
918 client_set_minimized(lua_State
*L
, int cidx
, bool s
)
920 client_t
*c
= luaA_client_checkudata(L
, cidx
);
922 if(c
->minimized
!= s
)
924 client_need_reban(c
);
926 client_need_reban(c
);
928 window_state_set(c
->window
, XCB_WM_STATE_ICONIC
);
930 window_state_set(c
->window
, XCB_WM_STATE_NORMAL
);
931 ewmh_client_update_hints(c
);
933 hook_property(c
, "minimized");
934 luaA_object_emit_signal(L
, cidx
, "property::minimized", 0);
938 /** Set a client sticky, or not.
939 * \param L The Lua VM state.
940 * \param cidx The client index.
941 * \param s Set or not the client sticky.
944 client_set_sticky(lua_State
*L
, int cidx
, bool s
)
946 client_t
*c
= luaA_client_checkudata(L
, cidx
);
950 client_need_reban(c
);
952 client_need_reban(c
);
953 ewmh_client_update_hints(c
);
954 hook_property(c
, "sticky");
955 luaA_object_emit_signal(L
, cidx
, "property::sticky", 0);
959 /** Set a client fullscreen, or not.
960 * \param L The Lua VM state.
961 * \param cidx The client index.
962 * \param s Set or not the client fullscreen.
965 client_set_fullscreen(lua_State
*L
, int cidx
, bool s
)
967 client_t
*c
= luaA_client_checkudata(L
, cidx
);
969 if(c
->fullscreen
!= s
)
973 /* become fullscreen! */
976 /* Make sure the current geometry is stored without titlebar. */
977 titlebar_ban(c
->titlebar
);
978 /* remove any max state */
979 client_set_maximized_horizontal(L
, cidx
, false);
980 client_set_maximized_vertical(L
, cidx
, false);
981 /* You can only be part of one of the special layers. */
982 client_set_below(L
, cidx
, false);
983 client_set_above(L
, cidx
, false);
984 client_set_ontop(L
, cidx
, false);
986 geometry
= screen_area_get(c
->screen
, false);
987 c
->geometries
.fullscreen
= c
->geometry
;
988 c
->border_width_fs
= c
->border_width
;
989 client_set_border_width(L
, cidx
, 0);
990 c
->fullscreen
= true;
994 geometry
= c
->geometries
.fullscreen
;
995 c
->fullscreen
= false;
996 client_set_border_width(L
, cidx
, c
->border_width_fs
);
998 client_resize(c
, geometry
, false);
1000 ewmh_client_update_hints(c
);
1001 hook_property(c
, "fullscreen");
1002 luaA_object_emit_signal(L
, cidx
, "property::fullscreen", 0);
1006 /** Set a client horizontally maximized.
1007 * \param L The Lua VM state.
1008 * \param cidx The client index.
1009 * \param s The maximized status.
1012 client_set_maximized_horizontal(lua_State
*L
, int cidx
, bool s
)
1014 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1016 if(c
->maximized_horizontal
!= s
)
1020 if((c
->maximized_horizontal
= s
))
1022 /* remove fullscreen mode */
1023 client_set_fullscreen(L
, cidx
, false);
1025 geometry
= screen_area_get(c
->screen
, true);
1026 geometry
.y
= c
->geometry
.y
;
1027 geometry
.height
= c
->geometry
.height
;
1028 c
->geometries
.max
.x
= c
->geometry
.x
;
1029 c
->geometries
.max
.width
= c
->geometry
.width
;
1033 geometry
= c
->geometry
;
1034 geometry
.x
= c
->geometries
.max
.x
;
1035 geometry
.width
= c
->geometries
.max
.width
;
1038 client_resize(c
, geometry
, c
->size_hints_honor
);
1040 ewmh_client_update_hints(c
);
1041 hook_property(c
, "maximized_horizontal");
1042 luaA_object_emit_signal(L
, cidx
, "property::maximized_horizontal", 0);
1046 /** Set a client vertically maximized.
1047 * \param L The Lua VM state.
1048 * \param cidx The client index.
1049 * \param s The maximized status.
1052 client_set_maximized_vertical(lua_State
*L
, int cidx
, bool s
)
1054 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1056 if(c
->maximized_vertical
!= s
)
1060 if((c
->maximized_vertical
= s
))
1062 /* remove fullscreen mode */
1063 client_set_fullscreen(L
, cidx
, false);
1065 geometry
= screen_area_get(c
->screen
, true);
1066 geometry
.x
= c
->geometry
.x
;
1067 geometry
.width
= c
->geometry
.width
;
1068 c
->geometries
.max
.y
= c
->geometry
.y
;
1069 c
->geometries
.max
.height
= c
->geometry
.height
;
1073 geometry
= c
->geometry
;
1074 geometry
.y
= c
->geometries
.max
.y
;
1075 geometry
.height
= c
->geometries
.max
.height
;
1078 client_resize(c
, geometry
, c
->size_hints_honor
);
1080 ewmh_client_update_hints(c
);
1081 hook_property(c
, "maximized_vertical");
1082 luaA_object_emit_signal(L
, cidx
, "property::maximized_vertical", 0);
1086 /** Set a client above, or not.
1087 * \param L The Lua VM state.
1088 * \param cidx The client index.
1089 * \param s Set or not the client above.
1092 client_set_above(lua_State
*L
, int cidx
, bool s
)
1094 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1098 /* You can only be part of one of the special layers. */
1101 client_set_below(L
, cidx
, false);
1102 client_set_ontop(L
, cidx
, false);
1103 client_set_fullscreen(L
, cidx
, false);
1107 ewmh_client_update_hints(c
);
1109 hook_property(c
, "above");
1110 luaA_object_emit_signal(L
, cidx
, "property::above", 0);
1114 /** Set a client below, or not.
1115 * \param L The Lua VM state.
1116 * \param cidx The client index.
1117 * \param s Set or not the client below.
1120 client_set_below(lua_State
*L
, int cidx
, bool s
)
1122 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1126 /* You can only be part of one of the special layers. */
1129 client_set_above(L
, cidx
, false);
1130 client_set_ontop(L
, cidx
, false);
1131 client_set_fullscreen(L
, cidx
, false);
1135 ewmh_client_update_hints(c
);
1137 hook_property(c
, "below");
1138 luaA_object_emit_signal(L
, cidx
, "property::below", 0);
1142 /** Set a client modal, or not.
1143 * \param L The Lua VM state.
1144 * \param cidx The client index.
1145 * \param s Set or not the client modal attribute.
1148 client_set_modal(lua_State
*L
, int cidx
, bool s
)
1150 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1156 ewmh_client_update_hints(c
);
1158 hook_property(c
, "modal");
1159 luaA_object_emit_signal(L
, cidx
, "property::modal", 0);
1163 /** Set a client ontop, or not.
1164 * \param L The Lua VM state.
1165 * \param cidx The client index.
1166 * \param s Set or not the client ontop attribute.
1169 client_set_ontop(lua_State
*L
, int cidx
, bool s
)
1171 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1175 /* You can only be part of one of the special layers. */
1178 client_set_above(L
, cidx
, false);
1179 client_set_below(L
, cidx
, false);
1180 client_set_fullscreen(L
, cidx
, false);
1185 hook_property(c
, "ontop");
1186 luaA_object_emit_signal(L
, cidx
, "property::ontop", 0);
1190 /** Set a client skip taskbar attribute.
1191 * \param L Tha Lua VM state.
1192 * \param cidx The client index.
1193 * \param s Set or not the client skip taskbar attribute.
1196 client_set_skip_taskbar(lua_State
*L
, int cidx
, bool s
)
1198 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1200 if(c
->skip_taskbar
!= s
)
1202 c
->skip_taskbar
= s
;
1203 ewmh_client_update_hints(c
);
1204 luaA_object_emit_signal(L
, cidx
, "property::skip_taskbar", 0);
1208 /** Unban a client and move it back into the viewport.
1209 * \param c The client.
1212 client_unban(client_t
*c
)
1216 xcb_map_window(globalconf
.connection
, c
->window
);
1218 c
->isbanned
= false;
1222 /** Unmanage a client.
1223 * \param c The client.
1226 client_unmanage(client_t
*c
)
1228 tag_array_t
*tags
= &c
->screen
->tags
;
1230 /* Reset transient_for attributes of widows that maybe refering to us */
1231 foreach(_tc
, globalconf
.clients
)
1233 client_t
*tc
= *_tc
;
1234 if(tc
->transient_for
== c
)
1235 tc
->transient_for
= NULL
;
1238 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1239 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1241 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1244 /* remove client from global list and everywhere else */
1245 foreach(elem
, globalconf
.clients
)
1248 client_array_remove(&globalconf
.clients
, elem
);
1251 stack_client_remove(c
);
1252 for(int i
= 0; i
< tags
->len
; i
++)
1253 untag_client(c
, tags
->tab
[i
]);
1256 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1258 luaA_object_push(globalconf
.L
, c
);
1259 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1262 luaA_object_push(globalconf
.L
, c
);
1263 luaA_class_emit_signal(globalconf
.L
, &client_class
, "unmanage", 1);
1265 /* Call hook to notify list change */
1266 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1267 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1269 luaA_class_emit_signal(globalconf
.L
, &client_class
, "list", 0);
1271 window_state_set(c
->window
, XCB_WM_STATE_WITHDRAWN
);
1273 titlebar_client_detach(c
);
1275 ewmh_update_net_client_list(c
->phys_screen
);
1277 /* set client as invalid */
1280 luaA_object_unref(globalconf
.L
, c
);
1283 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1285 * \param c The client to kill.
1288 client_kill(client_t
*c
)
1290 if(client_hasproto(c
, WM_DELETE_WINDOW
))
1292 xcb_client_message_event_t ev
;
1294 /* Initialize all of event's fields first */
1297 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1298 ev
.window
= c
->window
;
1300 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1301 ev
.type
= WM_PROTOCOLS
;
1302 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1304 xcb_send_event(globalconf
.connection
, false, c
->window
,
1305 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1308 xcb_kill_client(globalconf
.connection
, c
->window
);
1311 /** Get all clients into a table.
1312 * \param L The Lua VM state.
1313 * \return The number of elements pushed on stack.
1315 * \lparam An optional screen nunmber.
1316 * \lreturn A table with all clients.
1319 luaA_client_get(lua_State
*L
)
1323 screen
= luaL_optnumber(L
, 1, 0) - 1;
1328 foreach(c
, globalconf
.clients
)
1330 luaA_object_push(L
, *c
);
1331 lua_rawseti(L
, -2, i
++);
1335 luaA_checkscreen(screen
);
1336 foreach(c
, globalconf
.clients
)
1337 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1339 luaA_object_push(L
, *c
);
1340 lua_rawseti(L
, -2, i
++);
1347 /** Check if a client is visible on its screen.
1348 * \param L The Lua VM state.
1349 * \return The number of elements pushed on stack.
1352 * \lreturn A boolean value, true if the client is visible, false otherwise.
1355 luaA_client_isvisible(lua_State
*L
)
1357 client_t
*c
= luaA_client_checkudata(L
, 1);
1358 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1362 /** Set client border width.
1363 * \param L The Lua VM state.
1364 * \param cidx The client index.
1365 * \param width The border width.
1368 client_set_border_width(lua_State
*L
, int cidx
, int width
)
1370 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1373 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1374 || c
->type
== WINDOW_TYPE_SPLASH
1375 || c
->type
== WINDOW_TYPE_DESKTOP
1379 if(width
== c
->border_width
|| width
< 0)
1382 /* disallow change of border width if the client is fullscreen */
1386 /* Update geometry with the new border. */
1387 c
->geometry
.width
-= 2 * c
->border_width
;
1388 c
->geometry
.height
-= 2 * c
->border_width
;
1390 c
->border_width
= width
;
1391 xcb_configure_window(globalconf
.connection
, c
->window
,
1392 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1394 c
->geometry
.width
+= 2 * c
->border_width
;
1395 c
->geometry
.height
+= 2 * c
->border_width
;
1397 /* Changing border size also affects the size of the titlebar. */
1398 titlebar_update_geometry(c
);
1400 hook_property(c
, "border_width");
1401 luaA_object_emit_signal(L
, cidx
, "property::border_width", 0);
1404 /** Set a client icon.
1405 * \param L The Lua VM state.
1406 * \param cidx The client index on the stack.
1407 * \param iidx The image index on the stack.
1410 client_set_icon(lua_State
*L
, int cidx
, int iidx
)
1412 client_t
*c
= luaA_client_checkudata(L
, cidx
);
1413 /* convert index to absolute */
1414 cidx
= luaA_absindex(L
, cidx
);
1415 iidx
= luaA_absindex(L
, iidx
);
1416 luaA_checkudata(L
, iidx
, &image_class
);
1417 luaA_object_unref_item(L
, cidx
, c
->icon
);
1418 c
->icon
= luaA_object_ref_item(L
, cidx
, iidx
);
1419 luaA_object_emit_signal(L
, cidx
< iidx
? cidx
: cidx
- 1, "property::icon", 0);
1421 hook_property(c
, "icon");
1425 * \param L The Lua VM state.
1431 luaA_client_kill(lua_State
*L
)
1433 client_t
*c
= luaA_client_checkudata(L
, 1);
1438 /** Swap a client with another one.
1439 * \param L The Lua VM state.
1442 * \lparam A client to swap with.
1445 luaA_client_swap(lua_State
*L
)
1447 client_t
*c
= luaA_client_checkudata(L
, 1);
1448 client_t
*swap
= luaA_client_checkudata(L
, 2);
1452 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1453 foreach(item
, globalconf
.clients
)
1457 else if(*item
== swap
)
1459 if(ref_c
&& ref_swap
)
1466 /* Call hook to notify list change */
1467 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1468 luaA_dofunction_from_registry(L
, globalconf
.hooks
.clients
, 0, 0);
1470 luaA_class_emit_signal(globalconf
.L
, &client_class
, "list", 0);
1476 /** Access or set the client tags.
1477 * \param L The Lua VM state.
1478 * \return The number of elements pushed on stack.
1479 * \lparam A table with tags to set, or none to get the current tags table.
1480 * \return The clients tag.
1483 luaA_client_tags(lua_State
*L
)
1485 client_t
*c
= luaA_client_checkudata(L
, 1);
1486 tag_array_t
*tags
= &c
->screen
->tags
;
1489 if(lua_gettop(L
) == 2)
1491 luaA_checktable(L
, 2);
1492 for(int i
= 0; i
< tags
->len
; i
++)
1493 untag_client(c
, tags
->tab
[i
]);
1495 while(lua_next(L
, 2))
1502 if(is_client_tagged(c
, *tag
))
1504 luaA_object_push(L
, *tag
);
1505 lua_rawseti(L
, -2, ++j
);
1511 /** Raise a client on top of others which are on the same layer.
1512 * \param L The Lua VM state.
1517 luaA_client_raise(lua_State
*L
)
1519 client_t
*c
= luaA_client_checkudata(L
, 1);
1524 /** Lower a client on bottom of others which are on the same layer.
1525 * \param L The Lua VM state.
1530 luaA_client_lower(lua_State
*L
)
1532 client_t
*c
= luaA_client_checkudata(L
, 1);
1537 /** Redraw a client by unmapping and mapping it quickly.
1538 * \param L The Lua VM state.
1544 luaA_client_redraw(lua_State
*L
)
1546 client_t
*c
= luaA_client_checkudata(L
, 1);
1548 xcb_unmap_window(globalconf
.connection
, c
->window
);
1549 xcb_map_window(globalconf
.connection
, c
->window
);
1551 /* Set the focus on the current window if the redraw has been
1552 performed on the window where the pointer is currently on
1553 because after the unmapping/mapping, the focus is lost */
1554 if(globalconf
.screen_focus
->client_focus
== c
)
1563 /** Stop managing a client.
1564 * \param L The Lua VM state.
1565 * \return The number of elements pushed on stack.
1570 luaA_client_unmanage(lua_State
*L
)
1572 client_t
*c
= luaA_client_checkudata(L
, 1);
1577 /** Return client geometry.
1578 * \param L The Lua VM state.
1579 * \return The number of elements pushed on stack.
1581 * \lparam A table with new coordinates, or none.
1582 * \lreturn A table with client coordinates.
1585 luaA_client_geometry(lua_State
*L
)
1587 client_t
*c
= luaA_client_checkudata(L
, 1);
1589 if(lua_gettop(L
) == 2)
1593 luaA_checktable(L
, 2);
1594 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1595 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1596 if(client_isfixed(c
))
1598 geometry
.width
= c
->geometry
.width
;
1599 geometry
.height
= c
->geometry
.height
;
1603 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1604 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1607 client_resize(c
, geometry
, c
->size_hints_honor
);
1610 return luaA_pusharea(L
, c
->geometry
);
1613 /** Return client struts (reserved space at the edge of the screen).
1614 * \param L The Lua VM state.
1615 * \return The number of elements pushed on stack.
1617 * \lparam A table with new strut values, or none.
1618 * \lreturn A table with strut values.
1621 luaA_client_struts(lua_State
*L
)
1623 client_t
*c
= luaA_client_checkudata(L
, 1);
1625 if(lua_gettop(L
) == 2)
1627 luaA_tostrut(L
, 2, &c
->strut
);
1628 ewmh_update_strut(c
->window
, &c
->strut
);
1629 hook_property(c
, "struts");
1630 luaA_object_emit_signal(L
, 1, "property::struts", 0);
1631 screen_emit_signal(L
, c
->screen
, "property::workarea", 0);
1634 return luaA_pushstrut(L
, c
->strut
);
1638 luaA_client_set_screen(lua_State
*L
, client_t
*c
)
1640 if(globalconf
.xinerama_is_active
)
1642 int screen
= luaL_checknumber(L
, -1) - 1;
1643 luaA_checkscreen(screen
);
1644 screen_client_moveto(c
, &globalconf
.screens
.tab
[screen
], true);
1650 luaA_client_set_hidden(lua_State
*L
, client_t
*c
)
1652 bool b
= luaA_checkboolean(L
, -1);
1655 client_need_reban(c
);
1657 client_need_reban(c
);
1658 hook_property(c
, "hidden");
1659 luaA_object_emit_signal(L
, -3, "property::hidden", 0);
1665 luaA_client_set_minimized(lua_State
*L
, client_t
*c
)
1667 client_set_minimized(L
, -3, luaA_checkboolean(L
, -1));
1672 luaA_client_set_fullscreen(lua_State
*L
, client_t
*c
)
1674 client_set_fullscreen(L
, -3, luaA_checkboolean(L
, -1));
1679 luaA_client_set_modal(lua_State
*L
, client_t
*c
)
1681 client_set_modal(L
, -3, luaA_checkboolean(L
, -1));
1686 luaA_client_set_maximized_horizontal(lua_State
*L
, client_t
*c
)
1688 client_set_maximized_horizontal(L
, -3, luaA_checkboolean(L
, -1));
1693 luaA_client_set_maximized_vertical(lua_State
*L
, client_t
*c
)
1695 client_set_maximized_vertical(L
, -3, luaA_checkboolean(L
, -1));
1700 luaA_client_set_icon(lua_State
*L
, client_t
*c
)
1702 client_set_icon(L
, -3, -1);
1707 luaA_client_set_opacity(lua_State
*L
, client_t
*c
)
1709 if(lua_isnil(L
, -1))
1710 client_set_opacity(L
, -3, -1);
1712 client_set_opacity(L
, -3, luaL_checknumber(L
, -1));
1717 luaA_client_set_sticky(lua_State
*L
, client_t
*c
)
1719 client_set_sticky(L
, -3, luaA_checkboolean(L
, -1));
1724 luaA_client_set_size_hints_honor(lua_State
*L
, client_t
*c
)
1726 c
->size_hints_honor
= luaA_checkboolean(L
, -1);
1727 hook_property(c
, "size_hints_honor");
1728 luaA_object_emit_signal(L
, -3, "property::size_hints_honor", 0);
1733 luaA_client_set_border_width(lua_State
*L
, client_t
*c
)
1735 client_set_border_width(L
, -3, luaL_checknumber(L
, -1));
1740 luaA_client_set_ontop(lua_State
*L
, client_t
*c
)
1742 client_set_ontop(L
, -3, luaA_checkboolean(L
, -1));
1747 luaA_client_set_below(lua_State
*L
, client_t
*c
)
1749 client_set_below(L
, -3, luaA_checkboolean(L
, -1));
1754 luaA_client_set_above(lua_State
*L
, client_t
*c
)
1756 client_set_above(L
, -3, luaA_checkboolean(L
, -1));
1761 luaA_client_set_urgent(lua_State
*L
, client_t
*c
)
1763 client_set_urgent(L
, -3, luaA_checkboolean(L
, -1));
1768 luaA_client_set_border_color(lua_State
*L
, client_t
*c
)
1772 if((buf
= luaL_checklstring(L
, -1, &len
))
1773 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1775 xcb_change_window_attributes(globalconf
.connection
, c
->window
,
1776 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1777 luaA_object_emit_signal(L
, -3, "property::border_color", 0);
1783 luaA_client_set_titlebar(lua_State
*L
, client_t
*c
)
1785 if(lua_isnil(L
, -1))
1786 titlebar_client_detach(c
);
1788 titlebar_client_attach(c
);
1793 luaA_client_set_skip_taskbar(lua_State
*L
, client_t
*c
)
1795 client_set_skip_taskbar(L
, -3, luaA_checkboolean(L
, -1));
1800 luaA_client_get_name(lua_State
*L
, client_t
*c
)
1802 lua_pushstring(L
, c
->name
? c
->name
: c
->alt_name
);
1807 luaA_client_get_icon_name(lua_State
*L
, client_t
*c
)
1809 lua_pushstring(L
, c
->icon_name
? c
->icon_name
: c
->alt_icon_name
);
1813 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, class, lua_pushstring
)
1814 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, instance
, lua_pushstring
)
1815 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, machine
, lua_pushstring
)
1816 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, role
, lua_pushstring
)
1817 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, transient_for
, luaA_object_push
)
1818 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, skip_taskbar
, lua_pushboolean
)
1819 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, window
, lua_pushnumber
)
1820 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, leader_window
, lua_pushnumber
)
1821 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, group_window
, lua_pushnumber
)
1822 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, pid
, lua_pushnumber
)
1823 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, hidden
, lua_pushboolean
)
1824 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, minimized
, lua_pushboolean
)
1825 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, fullscreen
, lua_pushboolean
)
1826 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, modal
, lua_pushboolean
)
1827 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, ontop
, lua_pushboolean
)
1828 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, urgent
, lua_pushboolean
)
1829 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, above
, lua_pushboolean
)
1830 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, below
, lua_pushboolean
)
1831 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, sticky
, lua_pushboolean
)
1832 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, size_hints_honor
, lua_pushboolean
)
1833 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, maximized_horizontal
, lua_pushboolean
)
1834 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, maximized_vertical
, lua_pushboolean
)
1835 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, opacity
, lua_pushnumber
)
1836 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, border_width
, lua_pushnumber
)
1837 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, border_color
, luaA_pushxcolor
)
1840 luaA_client_get_content(lua_State
*L
, client_t
*c
)
1842 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
1845 c
->geometries
.internal
.width
,
1846 c
->geometries
.internal
.height
,
1847 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
1852 if(ximage
->bpp
>= 24)
1854 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
1856 for(int y
= 0; y
< ximage
->height
; y
++)
1857 for(int x
= 0; x
< ximage
->width
; x
++)
1859 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
1860 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
1863 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
1865 xcb_image_destroy(ximage
);
1872 luaA_client_get_type(lua_State
*L
, client_t
*c
)
1876 case WINDOW_TYPE_DESKTOP
:
1877 lua_pushliteral(L
, "desktop");
1879 case WINDOW_TYPE_DOCK
:
1880 lua_pushliteral(L
, "dock");
1882 case WINDOW_TYPE_SPLASH
:
1883 lua_pushliteral(L
, "splash");
1885 case WINDOW_TYPE_DIALOG
:
1886 lua_pushliteral(L
, "dialog");
1888 case WINDOW_TYPE_MENU
:
1889 lua_pushliteral(L
, "menu");
1891 case WINDOW_TYPE_TOOLBAR
:
1892 lua_pushliteral(L
, "toolbar");
1894 case WINDOW_TYPE_UTILITY
:
1895 lua_pushliteral(L
, "utility");
1897 case WINDOW_TYPE_DROPDOWN_MENU
:
1898 lua_pushliteral(L
, "dropdown_menu");
1900 case WINDOW_TYPE_POPUP_MENU
:
1901 lua_pushliteral(L
, "popup_menu");
1903 case WINDOW_TYPE_TOOLTIP
:
1904 lua_pushliteral(L
, "tooltip");
1906 case WINDOW_TYPE_NOTIFICATION
:
1907 lua_pushliteral(L
, "notification");
1909 case WINDOW_TYPE_COMBO
:
1910 lua_pushliteral(L
, "combo");
1912 case WINDOW_TYPE_DND
:
1913 lua_pushliteral(L
, "dnd");
1915 case WINDOW_TYPE_NORMAL
:
1916 lua_pushliteral(L
, "normal");
1923 luaA_client_get_screen(lua_State
*L
, client_t
*c
)
1927 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1932 luaA_client_get_icon(lua_State
*L
, client_t
*c
)
1934 return luaA_object_push_item(L
, -2, c
->icon
);
1938 luaA_client_get_titlebar(lua_State
*L
, client_t
*c
)
1940 return luaA_object_push(L
, c
->titlebar
);
1944 luaA_client_get_size_hints(lua_State
*L
, client_t
*c
)
1946 const char *u_or_p
= NULL
;
1948 lua_createtable(L
, 0, 1);
1950 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1951 u_or_p
= "user_position";
1952 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1953 u_or_p
= "program_position";
1957 lua_createtable(L
, 0, 2);
1958 lua_pushnumber(L
, c
->size_hints
.x
);
1959 lua_setfield(L
, -2, "x");
1960 lua_pushnumber(L
, c
->size_hints
.y
);
1961 lua_setfield(L
, -2, "y");
1962 lua_setfield(L
, -2, u_or_p
);
1966 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1967 u_or_p
= "user_size";
1968 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1969 u_or_p
= "program_size";
1973 lua_createtable(L
, 0, 2);
1974 lua_pushnumber(L
, c
->size_hints
.width
);
1975 lua_setfield(L
, -2, "width");
1976 lua_pushnumber(L
, c
->size_hints
.height
);
1977 lua_setfield(L
, -2, "height");
1978 lua_setfield(L
, -2, u_or_p
);
1981 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1983 lua_pushnumber(L
, c
->size_hints
.min_width
);
1984 lua_setfield(L
, -2, "min_width");
1985 lua_pushnumber(L
, c
->size_hints
.min_height
);
1986 lua_setfield(L
, -2, "min_height");
1989 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1991 lua_pushnumber(L
, c
->size_hints
.max_width
);
1992 lua_setfield(L
, -2, "max_width");
1993 lua_pushnumber(L
, c
->size_hints
.max_height
);
1994 lua_setfield(L
, -2, "max_height");
1997 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1999 lua_pushnumber(L
, c
->size_hints
.width_inc
);
2000 lua_setfield(L
, -2, "width_inc");
2001 lua_pushnumber(L
, c
->size_hints
.height_inc
);
2002 lua_setfield(L
, -2, "height_inc");
2005 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
2007 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
2008 lua_setfield(L
, -2, "min_aspect_num");
2009 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
2010 lua_setfield(L
, -2, "min_aspect_den");
2011 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
2012 lua_setfield(L
, -2, "max_aspect_num");
2013 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
2014 lua_setfield(L
, -2, "max_aspect_den");
2017 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
2019 lua_pushnumber(L
, c
->size_hints
.base_width
);
2020 lua_setfield(L
, -2, "base_width");
2021 lua_pushnumber(L
, c
->size_hints
.base_height
);
2022 lua_setfield(L
, -2, "base_height");
2025 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
2027 switch(c
->size_hints
.win_gravity
)
2030 lua_pushliteral(L
, "north_west");
2032 case XCB_GRAVITY_NORTH
:
2033 lua_pushliteral(L
, "north");
2035 case XCB_GRAVITY_NORTH_EAST
:
2036 lua_pushliteral(L
, "north_east");
2038 case XCB_GRAVITY_WEST
:
2039 lua_pushliteral(L
, "west");
2041 case XCB_GRAVITY_CENTER
:
2042 lua_pushliteral(L
, "center");
2044 case XCB_GRAVITY_EAST
:
2045 lua_pushliteral(L
, "east");
2047 case XCB_GRAVITY_SOUTH_WEST
:
2048 lua_pushliteral(L
, "south_west");
2050 case XCB_GRAVITY_SOUTH
:
2051 lua_pushliteral(L
, "south");
2053 case XCB_GRAVITY_SOUTH_EAST
:
2054 lua_pushliteral(L
, "south_east");
2056 case XCB_GRAVITY_STATIC
:
2057 lua_pushliteral(L
, "static");
2060 lua_setfield(L
, -2, "win_gravity");
2066 /** Get or set mouse buttons bindings for a client.
2067 * \param L The Lua VM state.
2068 * \return The number of element pushed on stack.
2071 * \lparam An array of mouse button bindings objects, or nothing.
2072 * \return The array of mouse button bindings objects of this client.
2075 luaA_client_buttons(lua_State
*L
)
2077 client_t
*client
= luaA_client_checkudata(L
, 1);
2078 button_array_t
*buttons
= &client
->buttons
;
2080 if(lua_gettop(L
) == 2)
2082 luaA_button_array_set(L
, 1, 2, buttons
);
2083 luaA_object_emit_signal(L
, 1, "property::buttons", 0);
2084 window_buttons_grab(client
->window
, &client
->buttons
);
2087 return luaA_button_array_get(L
, 1, buttons
);
2090 /** Get or set keys bindings for a client.
2091 * \param L The Lua VM state.
2092 * \return The number of element pushed on stack.
2095 * \lparam An array of key bindings objects, or nothing.
2096 * \return The array of key bindings objects of this client.
2099 luaA_client_keys(lua_State
*L
)
2101 client_t
*c
= luaA_client_checkudata(L
, 1);
2102 key_array_t
*keys
= &c
->keys
;
2104 if(lua_gettop(L
) == 2)
2106 luaA_key_array_set(L
, 1, 2, keys
);
2107 luaA_object_emit_signal(L
, 1, "property::keys", 0);
2108 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->window
, XCB_BUTTON_MASK_ANY
);
2109 window_grabkeys(c
->window
, keys
);
2112 return luaA_key_array_get(L
, 1, keys
);
2116 * \param L The Lua VM state.
2117 * \return The number of pushed elements.
2120 luaA_client_module_index(lua_State
*L
)
2123 const char *buf
= luaL_checklstring(L
, 2, &len
);
2125 switch(a_tokenize(buf
, len
))
2128 return luaA_object_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
2135 /* Client module new index.
2136 * \param L The Lua VM state.
2137 * \return The number of pushed elements.
2140 luaA_client_module_newindex(lua_State
*L
)
2143 const char *buf
= luaL_checklstring(L
, 2, &len
);
2146 switch(a_tokenize(buf
, len
))
2149 c
= luaA_client_checkudata(L
, 3);
2160 client_class_setup(lua_State
*L
)
2162 static const struct luaL_reg client_methods
[] =
2164 LUA_CLASS_METHODS(client
)
2165 { "get", luaA_client_get
},
2166 { "__index", luaA_client_module_index
},
2167 { "__newindex", luaA_client_module_newindex
},
2171 static const struct luaL_reg client_meta
[] =
2173 LUA_OBJECT_META(client
)
2175 { "buttons", luaA_client_buttons
},
2176 { "keys", luaA_client_keys
},
2177 { "isvisible", luaA_client_isvisible
},
2178 { "geometry", luaA_client_geometry
},
2179 { "struts", luaA_client_struts
},
2180 { "tags", luaA_client_tags
},
2181 { "kill", luaA_client_kill
},
2182 { "swap", luaA_client_swap
},
2183 { "raise", luaA_client_raise
},
2184 { "lower", luaA_client_lower
},
2185 { "redraw", luaA_client_redraw
},
2186 { "unmanage", luaA_client_unmanage
},
2187 { "__gc", luaA_client_gc
},
2191 luaA_class_setup(L
, &client_class
, "client", (lua_class_allocator_t
) client_new
,
2192 luaA_class_index_miss_property
, luaA_class_newindex_miss_property
,
2193 client_methods
, client_meta
);
2194 luaA_class_add_property(&client_class
, A_TK_NAME
,
2196 (lua_class_propfunc_t
) luaA_client_get_name
,
2198 luaA_class_add_property(&client_class
, A_TK_TRANSIENT_FOR
,
2200 (lua_class_propfunc_t
) luaA_client_get_transient_for
,
2202 luaA_class_add_property(&client_class
, A_TK_SKIP_TASKBAR
,
2203 (lua_class_propfunc_t
) luaA_client_set_skip_taskbar
,
2204 (lua_class_propfunc_t
) luaA_client_get_skip_taskbar
,
2205 (lua_class_propfunc_t
) luaA_client_set_skip_taskbar
);
2206 luaA_class_add_property(&client_class
, A_TK_CONTENT
,
2208 (lua_class_propfunc_t
) luaA_client_get_content
,
2210 luaA_class_add_property(&client_class
, A_TK_TYPE
,
2212 (lua_class_propfunc_t
) luaA_client_get_type
,
2214 luaA_class_add_property(&client_class
, A_TK_CLASS
,
2216 (lua_class_propfunc_t
) luaA_client_get_class
,
2218 luaA_class_add_property(&client_class
, A_TK_INSTANCE
,
2220 (lua_class_propfunc_t
) luaA_client_get_instance
,
2222 luaA_class_add_property(&client_class
, A_TK_ROLE
,
2224 (lua_class_propfunc_t
) luaA_client_get_role
,
2226 luaA_class_add_property(&client_class
, A_TK_PID
,
2228 (lua_class_propfunc_t
) luaA_client_get_pid
,
2230 luaA_class_add_property(&client_class
, A_TK_WINDOW
,
2232 (lua_class_propfunc_t
) luaA_client_get_window
,
2234 luaA_class_add_property(&client_class
, A_TK_LEADER_WINDOW
,
2236 (lua_class_propfunc_t
) luaA_client_get_leader_window
,
2238 luaA_class_add_property(&client_class
, A_TK_MACHINE
,
2240 (lua_class_propfunc_t
) luaA_client_get_machine
,
2242 luaA_class_add_property(&client_class
, A_TK_ICON_NAME
,
2244 (lua_class_propfunc_t
) luaA_client_get_icon_name
,
2246 luaA_class_add_property(&client_class
, A_TK_SCREEN
,
2248 (lua_class_propfunc_t
) luaA_client_get_screen
,
2249 (lua_class_propfunc_t
) luaA_client_set_screen
);
2250 luaA_class_add_property(&client_class
, A_TK_HIDDEN
,
2251 (lua_class_propfunc_t
) luaA_client_set_hidden
,
2252 (lua_class_propfunc_t
) luaA_client_get_hidden
,
2253 (lua_class_propfunc_t
) luaA_client_set_hidden
);
2254 luaA_class_add_property(&client_class
, A_TK_MINIMIZED
,
2255 (lua_class_propfunc_t
) luaA_client_set_minimized
,
2256 (lua_class_propfunc_t
) luaA_client_get_minimized
,
2257 (lua_class_propfunc_t
) luaA_client_set_minimized
);
2258 luaA_class_add_property(&client_class
, A_TK_FULLSCREEN
,
2259 (lua_class_propfunc_t
) luaA_client_set_fullscreen
,
2260 (lua_class_propfunc_t
) luaA_client_get_fullscreen
,
2261 (lua_class_propfunc_t
) luaA_client_set_fullscreen
);
2262 luaA_class_add_property(&client_class
, A_TK_MODAL
,
2263 (lua_class_propfunc_t
) luaA_client_set_modal
,
2264 (lua_class_propfunc_t
) luaA_client_get_modal
,
2265 (lua_class_propfunc_t
) luaA_client_set_modal
);
2266 luaA_class_add_property(&client_class
, A_TK_GROUP_WINDOW
,
2268 (lua_class_propfunc_t
) luaA_client_get_group_window
,
2270 luaA_class_add_property(&client_class
, A_TK_MAXIMIZED_HORIZONTAL
,
2271 (lua_class_propfunc_t
) luaA_client_set_maximized_horizontal
,
2272 (lua_class_propfunc_t
) luaA_client_get_maximized_horizontal
,
2273 (lua_class_propfunc_t
) luaA_client_set_maximized_horizontal
);
2274 luaA_class_add_property(&client_class
, A_TK_MAXIMIZED_VERTICAL
,
2275 (lua_class_propfunc_t
) luaA_client_set_maximized_vertical
,
2276 (lua_class_propfunc_t
) luaA_client_get_maximized_vertical
,
2277 (lua_class_propfunc_t
) luaA_client_set_maximized_vertical
);
2278 luaA_class_add_property(&client_class
, A_TK_ICON
,
2279 (lua_class_propfunc_t
) luaA_client_set_icon
,
2280 (lua_class_propfunc_t
) luaA_client_get_icon
,
2281 (lua_class_propfunc_t
) luaA_client_set_icon
);
2282 luaA_class_add_property(&client_class
, A_TK_OPACITY
,
2283 (lua_class_propfunc_t
) luaA_client_set_opacity
,
2284 (lua_class_propfunc_t
) luaA_client_get_opacity
,
2285 (lua_class_propfunc_t
) luaA_client_set_opacity
);
2286 luaA_class_add_property(&client_class
, A_TK_ONTOP
,
2287 (lua_class_propfunc_t
) luaA_client_set_ontop
,
2288 (lua_class_propfunc_t
) luaA_client_get_ontop
,
2289 (lua_class_propfunc_t
) luaA_client_set_ontop
);
2290 luaA_class_add_property(&client_class
, A_TK_ABOVE
,
2291 (lua_class_propfunc_t
) luaA_client_set_above
,
2292 (lua_class_propfunc_t
) luaA_client_get_above
,
2293 (lua_class_propfunc_t
) luaA_client_set_above
);
2294 luaA_class_add_property(&client_class
, A_TK_BELOW
,
2295 (lua_class_propfunc_t
) luaA_client_set_below
,
2296 (lua_class_propfunc_t
) luaA_client_get_below
,
2297 (lua_class_propfunc_t
) luaA_client_set_below
);
2298 luaA_class_add_property(&client_class
, A_TK_STICKY
,
2299 (lua_class_propfunc_t
) luaA_client_set_sticky
,
2300 (lua_class_propfunc_t
) luaA_client_get_sticky
,
2301 (lua_class_propfunc_t
) luaA_client_set_sticky
);
2302 luaA_class_add_property(&client_class
, A_TK_SIZE_HINTS_HONOR
,
2303 (lua_class_propfunc_t
) luaA_client_set_size_hints_honor
,
2304 (lua_class_propfunc_t
) luaA_client_get_size_hints_honor
,
2305 (lua_class_propfunc_t
) luaA_client_set_size_hints_honor
);
2306 luaA_class_add_property(&client_class
, A_TK_BORDER_WIDTH
,
2307 (lua_class_propfunc_t
) luaA_client_set_border_width
,
2308 (lua_class_propfunc_t
) luaA_client_get_border_width
,
2309 (lua_class_propfunc_t
) luaA_client_set_border_width
);
2310 luaA_class_add_property(&client_class
, A_TK_BORDER_COLOR
,
2311 (lua_class_propfunc_t
) luaA_client_set_border_color
,
2312 (lua_class_propfunc_t
) luaA_client_get_border_color
,
2313 (lua_class_propfunc_t
) luaA_client_set_border_color
);
2314 luaA_class_add_property(&client_class
, A_TK_TITLEBAR
,
2315 (lua_class_propfunc_t
) luaA_client_set_titlebar
,
2316 (lua_class_propfunc_t
) luaA_client_get_titlebar
,
2317 (lua_class_propfunc_t
) luaA_client_set_titlebar
);
2318 luaA_class_add_property(&client_class
, A_TK_URGENT
,
2319 (lua_class_propfunc_t
) luaA_client_set_urgent
,
2320 (lua_class_propfunc_t
) luaA_client_get_urgent
,
2321 (lua_class_propfunc_t
) luaA_client_set_urgent
);
2322 luaA_class_add_property(&client_class
, A_TK_SIZE_HINTS
,
2324 (lua_class_propfunc_t
) luaA_client_get_size_hints
,
2328 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80