2007-10-03 17:26:14 +02:00
|
|
|
/*
|
|
|
|
* client.c - client management
|
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-10-03 17:26:14 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2007-09-12 14:29:51 +02:00
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb_atom.h>
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-10-24 20:40:02 +02:00
|
|
|
#include "cnode.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
#include "window.h"
|
2007-12-27 18:01:36 +01:00
|
|
|
#include "ewmh.h"
|
2008-03-13 09:05:34 +01:00
|
|
|
#include "screen.h"
|
2008-03-15 13:59:04 +01:00
|
|
|
#include "titlebar.h"
|
2008-06-30 13:09:24 +02:00
|
|
|
#include "systray.h"
|
2008-09-16 14:09:56 +02:00
|
|
|
#include "property.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "layouts/floating.h"
|
2008-04-28 12:23:10 +02:00
|
|
|
#include "common/markup.h"
|
2008-06-30 18:55:14 +02:00
|
|
|
#include "common/atoms.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-10-26 16:15:49 +01:00
|
|
|
DO_LUA_NEW(extern, client_t, client, "client", client_ref)
|
2008-06-18 18:31:35 +02:00
|
|
|
DO_LUA_EQ(client_t, client, "client")
|
2008-07-31 17:29:05 +02:00
|
|
|
DO_LUA_GC(client_t, client, "client", client_unref)
|
2008-06-18 18:31:35 +02:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/** Load windows properties, restoring client's tag
|
2008-06-05 09:25:38 +02:00
|
|
|
* and floating state before awesome was restarted if any.
|
|
|
|
* \param c A client pointer.
|
2008-06-10 15:15:13 +02:00
|
|
|
* \param screen A virtual screen.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \return True if client had property, false otherwise.
|
2007-10-17 11:49:54 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
static bool
|
2008-06-10 15:15:13 +02:00
|
|
|
client_loadprops(client_t * c, screen_t *screen)
|
2007-10-16 22:40:02 +02:00
|
|
|
{
|
2008-07-01 14:44:19 +02:00
|
|
|
ssize_t len;
|
2008-06-23 17:37:19 +02:00
|
|
|
tag_array_t *tags = &screen->tags;
|
2008-04-28 22:56:16 +02:00
|
|
|
char *prop = NULL;
|
2008-08-25 16:38:45 +02:00
|
|
|
xcb_get_property_cookie_t floating_q, fullscreen_q;
|
|
|
|
xcb_get_property_reply_t *reply;
|
|
|
|
void *data;
|
2007-10-16 22:40:02 +02:00
|
|
|
|
2008-08-25 16:38:45 +02:00
|
|
|
if(!xutil_text_prop_get(globalconf.connection, c->win, _AWESOME_TAGS,
|
2008-08-11 13:27:28 +02:00
|
|
|
&prop, &len))
|
2008-06-23 17:37:19 +02:00
|
|
|
return false;
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2008-08-25 16:38:45 +02:00
|
|
|
/* Send the GetProperty requests which will be processed later */
|
|
|
|
floating_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
_AWESOME_FLOATING, CARDINAL, 0, 1);
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2008-08-25 16:38:45 +02:00
|
|
|
fullscreen_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
_AWESOME_FULLSCREEN, CARDINAL, 0, 1);
|
|
|
|
|
|
|
|
/* ignore property if the tag count isn't matching */
|
|
|
|
if(len == tags->len)
|
|
|
|
for(int i = 0; i < tags->len; i++)
|
|
|
|
if(prop[i] == '1')
|
|
|
|
tag_client(c, tags->tab[i]);
|
|
|
|
else
|
|
|
|
untag_client(c, tags->tab[i]);
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2008-06-23 17:37:19 +02:00
|
|
|
p_delete(&prop);
|
2008-08-25 16:38:45 +02:00
|
|
|
|
|
|
|
/* check for floating */
|
|
|
|
reply = xcb_get_property_reply(globalconf.connection, floating_q, NULL);
|
|
|
|
|
|
|
|
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
|
|
|
client_setfloating(c, *(bool *) data);
|
|
|
|
p_delete(&reply);
|
|
|
|
|
|
|
|
/* check for fullscreen */
|
|
|
|
reply = xcb_get_property_reply(globalconf.connection, fullscreen_q, NULL);
|
|
|
|
|
|
|
|
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
|
|
|
client_setfullscreen(c, *(bool *) data);
|
|
|
|
p_delete(&reply);
|
|
|
|
|
2008-06-23 17:37:19 +02:00
|
|
|
return true;
|
2007-10-16 22:40:02 +02:00
|
|
|
}
|
|
|
|
|
2008-10-11 09:38:48 +02:00
|
|
|
/** Check if client supports protocol a protocole in WM_PROTOCOL.
|
2008-04-29 09:14:46 +02:00
|
|
|
* \param win The window.
|
2008-10-11 09:38:48 +02:00
|
|
|
* \return True if client has the atom in protocol, false otherwise.
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
static bool
|
2008-10-11 09:38:48 +02:00
|
|
|
window_hasproto(xcb_window_t win, xcb_atom_t atom)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-09-09 16:14:36 +02:00
|
|
|
uint32_t i;
|
|
|
|
xcb_get_wm_protocols_reply_t protocols;
|
2008-03-21 16:50:17 +01:00
|
|
|
bool ret = false;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-09-09 16:14:36 +02:00
|
|
|
if(xcb_get_wm_protocols_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_protocols_unchecked(globalconf.connection,
|
|
|
|
win, WM_PROTOCOLS),
|
|
|
|
&protocols, NULL))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-09-09 16:14:36 +02:00
|
|
|
for(i = 0; !ret && i < protocols.atoms_len; i++)
|
2008-10-11 09:38:48 +02:00
|
|
|
if(protocols.atoms[i] == atom)
|
2008-03-21 16:50:17 +01:00
|
|
|
ret = true;
|
2008-09-09 16:14:36 +02:00
|
|
|
xcb_get_wm_protocols_reply_wipe(&protocols);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/** Returns true if a client is tagged
|
|
|
|
* with one of the tags of the specified screen.
|
2008-04-29 09:14:46 +02:00
|
|
|
* \param c The client to check.
|
|
|
|
* \param screen Virtual screen number.
|
2008-06-09 21:43:09 +02:00
|
|
|
* \return true if the client is visible, false otherwise.
|
2008-04-09 17:33:47 +02:00
|
|
|
*/
|
|
|
|
bool
|
2008-08-11 11:57:57 +02:00
|
|
|
client_maybevisible(client_t *c, int screen)
|
2008-04-09 17:33:47 +02:00
|
|
|
{
|
2008-08-11 11:57:57 +02:00
|
|
|
if(c->screen == screen)
|
2008-06-23 17:37:19 +02:00
|
|
|
{
|
2008-09-03 14:59:18 +02:00
|
|
|
if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
|
2008-08-21 16:29:53 +02:00
|
|
|
return true;
|
|
|
|
|
2008-06-23 17:37:19 +02:00
|
|
|
tag_array_t *tags = &globalconf.screens[screen].tags;
|
2008-08-21 16:29:53 +02:00
|
|
|
|
2008-06-23 17:37:19 +02:00
|
|
|
for(int i = 0; i < tags->len; i++)
|
|
|
|
if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
|
2008-06-09 21:43:09 +02:00
|
|
|
return true;
|
2008-06-23 17:37:19 +02:00
|
|
|
}
|
2008-04-09 17:33:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-06-10 19:29:53 +02:00
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
/** Get a client by its window.
|
|
|
|
* \param w The client window to find.
|
2008-04-29 09:14:46 +02:00
|
|
|
* \return A client pointer if found, NULL otherwise.
|
2007-12-14 14:29:32 +01:00
|
|
|
*/
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *
|
2008-06-05 09:25:38 +02:00
|
|
|
client_getbywin(xcb_window_t w)
|
2007-12-14 14:29:32 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-06-05 09:25:38 +02:00
|
|
|
for(c = globalconf.clients; c && c->win != w; c = c->next);
|
2007-12-14 14:29:32 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Unfocus a client.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
2008-01-25 12:55:44 +01:00
|
|
|
static void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_unfocus(client_t *c)
|
2008-01-25 12:55:44 +01:00
|
|
|
{
|
2008-11-20 22:11:13 +01:00
|
|
|
xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
|
2008-09-06 09:18:23 +02:00
|
|
|
globalconf.screens[c->phys_screen].client_focus = NULL;
|
2008-07-29 14:57:18 +02:00
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/* Set focus on root window, so no events leak to the current window. */
|
|
|
|
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
|
|
root_win, XCB_CURRENT_TIME);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* Call hook */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.unfocus != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, c);
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
|
|
|
|
}
|
2008-05-20 15:39:47 +02:00
|
|
|
|
2008-06-17 23:20:03 +02:00
|
|
|
ewmh_update_net_active_window(c->phys_screen);
|
2008-01-25 12:55:44 +01:00
|
|
|
}
|
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/** Ban client and move it out of the viewport.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \param c The client.
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_ban(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-11-20 22:11:13 +01:00
|
|
|
if(!c->isbanned)
|
|
|
|
{
|
|
|
|
/* Move all clients out of the physical viewport into negative coordinate space. */
|
|
|
|
/* They will all be put on top of each other. */
|
|
|
|
uint32_t request[2] = { - (c->geometry.width + 2 * c->border),
|
|
|
|
- (c->geometry.height + 2 * c->border) };
|
|
|
|
|
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
request);
|
|
|
|
|
|
|
|
/* Do it manually because client geometry remains unchanged. */
|
|
|
|
if (c->titlebar)
|
|
|
|
{
|
|
|
|
simple_window_t *sw = &c->titlebar->sw;
|
|
|
|
|
|
|
|
if (sw->window)
|
|
|
|
{
|
|
|
|
request[0] = - (sw->geometry.width);
|
|
|
|
request[1] = - (sw->geometry.height);
|
|
|
|
/* Move the titlebar to the same place as the window. */
|
|
|
|
xcb_configure_window(globalconf.connection, sw->window,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c->isbanned = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait until the last moment to take away the focus from the window. */
|
|
|
|
if (globalconf.screens[c->phys_screen].client_focus == c)
|
2008-01-25 12:55:44 +01:00
|
|
|
client_unfocus(c);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-20 08:32:46 +02:00
|
|
|
/** Give focus to client, or to first client if client is NULL.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \param c The client or NULL.
|
2008-06-09 21:43:09 +02:00
|
|
|
* \return True if a window (even root) has received focus, false otherwise.
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
2008-08-11 11:51:54 +02:00
|
|
|
static void
|
|
|
|
client_focus(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-09-03 16:51:46 +02:00
|
|
|
if(!client_maybevisible(c, c->screen) || c->nofocus)
|
2008-08-11 11:51:54 +02:00
|
|
|
return;
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
/* unfocus current selected client */
|
2008-08-11 11:51:54 +02:00
|
|
|
if(globalconf.screen_focus->client_focus
|
|
|
|
&& c != globalconf.screen_focus->client_focus)
|
2008-07-31 15:51:28 +02:00
|
|
|
client_unfocus(globalconf.screen_focus->client_focus);
|
2007-12-14 21:51:54 +01:00
|
|
|
|
2008-08-11 11:51:54 +02:00
|
|
|
/* stop hiding c */
|
|
|
|
c->ishidden = false;
|
2008-09-18 13:51:10 +02:00
|
|
|
client_setminimized(c, false);
|
2008-07-31 15:51:28 +02:00
|
|
|
|
2008-08-11 11:51:54 +02:00
|
|
|
/* unban the client before focusing or it will fail */
|
|
|
|
client_unban(c);
|
2008-07-31 15:51:28 +02:00
|
|
|
|
2008-09-06 09:18:23 +02:00
|
|
|
globalconf.screen_focus = &globalconf.screens[c->phys_screen];
|
2008-08-11 11:51:54 +02:00
|
|
|
globalconf.screen_focus->client_focus = c;
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2008-08-11 11:51:54 +02:00
|
|
|
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
|
|
c->win, XCB_CURRENT_TIME);
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2008-08-11 11:51:54 +02:00
|
|
|
/* Some layouts use focused client differently, so call them back.
|
|
|
|
* And anyway, we have maybe unhidden */
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(c);
|
2008-08-11 11:51:54 +02:00
|
|
|
|
|
|
|
/* execute hook */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.focus != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
|
|
|
|
}
|
2007-12-28 13:43:47 +01:00
|
|
|
|
2008-08-11 11:51:54 +02:00
|
|
|
ewmh_update_net_active_window(c->phys_screen);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-08-21 17:52:44 +02:00
|
|
|
/** Stack a window below.
|
|
|
|
* \param c The client.
|
|
|
|
* \param previous The previous window on the stack.
|
|
|
|
* \param return The next-previous!
|
|
|
|
*/
|
|
|
|
static xcb_window_t
|
2008-11-10 12:32:04 +01:00
|
|
|
client_stack_above(client_t *c, xcb_window_t previous)
|
2008-08-21 17:52:44 +02:00
|
|
|
{
|
|
|
|
uint32_t config_win_vals[2];
|
|
|
|
|
|
|
|
config_win_vals[0] = previous;
|
2008-11-10 12:32:04 +01:00
|
|
|
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
|
2008-08-21 17:52:44 +02:00
|
|
|
|
2008-11-18 10:39:42 +01:00
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
|
|
|
|
config_win_vals[0] = c->win;
|
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
if(c->titlebar)
|
2008-08-21 17:52:44 +02:00
|
|
|
{
|
|
|
|
xcb_configure_window(globalconf.connection,
|
2008-09-20 21:24:16 +02:00
|
|
|
c->titlebar->sw.window,
|
2008-08-21 17:52:44 +02:00
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
2008-11-18 10:39:42 +01:00
|
|
|
previous = c->titlebar->sw.window;
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
2008-11-18 10:39:42 +01:00
|
|
|
else
|
|
|
|
previous = c->win;
|
2008-11-10 12:32:04 +01:00
|
|
|
|
|
|
|
/* stack transient window on top of their parents */
|
|
|
|
for(client_node_t *node = *client_node_list_last(&globalconf.stack);
|
|
|
|
node; node = node->prev)
|
|
|
|
if(node->client->transient_for == c)
|
|
|
|
{
|
|
|
|
client_stack_above(node->client,
|
|
|
|
previous);
|
|
|
|
previous = node->client->win;
|
|
|
|
}
|
|
|
|
|
|
|
|
return previous;
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
|
2008-10-21 17:33:16 +02:00
|
|
|
/** Stacking layout layers */
|
|
|
|
typedef enum
|
|
|
|
{
|
2008-11-03 11:46:57 +01:00
|
|
|
/** This one is a special layer */
|
2008-11-10 12:32:04 +01:00
|
|
|
LAYER_IGNORE,
|
2008-11-03 11:46:57 +01:00
|
|
|
LAYER_DESKTOP,
|
2008-10-21 17:33:16 +02:00
|
|
|
LAYER_BELOW,
|
|
|
|
LAYER_TILE,
|
|
|
|
LAYER_FLOAT,
|
|
|
|
LAYER_ABOVE,
|
|
|
|
LAYER_FULLSCREEN,
|
|
|
|
LAYER_ONTOP,
|
|
|
|
LAYER_OUTOFSPACE
|
|
|
|
} layer_t;
|
|
|
|
|
2008-08-21 17:52:44 +02:00
|
|
|
/** Get the real layer of a client according to its attribute (fullscreen, …)
|
|
|
|
* \param c The client.
|
|
|
|
* \return The real layer.
|
|
|
|
*/
|
|
|
|
static layer_t
|
|
|
|
client_layer_translator(client_t *c)
|
|
|
|
{
|
2008-11-17 09:56:34 +01:00
|
|
|
/* first deal with user set attributes */
|
2008-08-21 17:52:44 +02:00
|
|
|
if(c->isontop)
|
|
|
|
return LAYER_ONTOP;
|
|
|
|
else if(c->isfullscreen)
|
|
|
|
return LAYER_FULLSCREEN;
|
|
|
|
else if(c->isabove)
|
|
|
|
return LAYER_ABOVE;
|
2008-11-17 09:56:34 +01:00
|
|
|
else if(c->isbelow)
|
|
|
|
return LAYER_BELOW;
|
|
|
|
else if(c->isfloating)
|
2008-08-21 17:52:44 +02:00
|
|
|
return LAYER_FLOAT;
|
2008-11-17 09:56:34 +01:00
|
|
|
|
|
|
|
/* check for transient attr */
|
|
|
|
if(c->transient_for)
|
2008-11-10 12:32:04 +01:00
|
|
|
return LAYER_IGNORE;
|
2008-09-03 14:59:18 +02:00
|
|
|
|
2008-11-17 09:56:34 +01:00
|
|
|
/* then deal with windows type */
|
2008-09-03 14:59:18 +02:00
|
|
|
switch(c->type)
|
|
|
|
{
|
|
|
|
case WINDOW_TYPE_DOCK:
|
2008-09-08 00:00:22 +02:00
|
|
|
return LAYER_ABOVE;
|
2008-09-03 14:59:18 +02:00
|
|
|
case WINDOW_TYPE_DESKTOP:
|
|
|
|
return LAYER_DESKTOP;
|
2008-11-06 16:04:20 +01:00
|
|
|
case WINDOW_TYPE_DIALOG:
|
|
|
|
return LAYER_FLOAT;
|
2008-09-03 14:59:18 +02:00
|
|
|
default:
|
2008-11-17 09:56:34 +01:00
|
|
|
break;
|
2008-09-03 14:59:18 +02:00
|
|
|
}
|
2008-11-17 09:56:34 +01:00
|
|
|
|
|
|
|
if(client_isfixed(c))
|
|
|
|
return LAYER_FLOAT;
|
|
|
|
|
|
|
|
return LAYER_TILE;
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
|
2008-06-27 22:49:54 +02:00
|
|
|
/** Restack clients.
|
2008-05-25 19:30:54 +02:00
|
|
|
* \todo It might be worth stopping to restack everyone and only stack `c'
|
2008-06-05 09:25:38 +02:00
|
|
|
* relatively to the first matching in the list.
|
2008-05-25 19:30:54 +02:00
|
|
|
*/
|
2008-08-05 16:59:54 +02:00
|
|
|
void
|
2008-09-24 12:13:21 +02:00
|
|
|
client_stack()
|
2008-03-24 16:34:41 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
uint32_t config_win_vals[2];
|
2008-11-03 11:46:57 +01:00
|
|
|
client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
|
2008-04-10 11:52:03 +02:00
|
|
|
layer_t layer;
|
2008-06-19 19:51:58 +02:00
|
|
|
int screen;
|
2008-04-08 19:52:59 +02:00
|
|
|
|
2008-06-23 14:53:31 +02:00
|
|
|
config_win_vals[0] = XCB_NONE;
|
2008-11-03 11:46:57 +01:00
|
|
|
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
|
2008-06-25 13:41:25 +02:00
|
|
|
|
2008-11-17 09:58:43 +01:00
|
|
|
/* stack desktop windows */
|
|
|
|
for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
|
|
|
|
for(node = last; node; node = node->prev)
|
|
|
|
if(client_layer_translator(node->client) == layer)
|
|
|
|
config_win_vals[0] = client_stack_above(node->client,
|
|
|
|
config_win_vals[0]);
|
|
|
|
|
2008-11-03 11:46:57 +01:00
|
|
|
/* first stack not ontop wibox window */
|
2008-09-18 16:03:05 +02:00
|
|
|
for(screen = 0; screen < globalconf.nscreen; screen++)
|
2008-09-24 12:13:21 +02:00
|
|
|
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
2008-09-20 16:45:43 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
|
2008-11-03 11:46:57 +01:00
|
|
|
if(!sb->ontop)
|
2008-09-22 19:23:28 +02:00
|
|
|
{
|
|
|
|
xcb_configure_window(globalconf.connection,
|
|
|
|
sb->sw.window,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] = sb->sw.window;
|
|
|
|
}
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-06-19 19:51:58 +02:00
|
|
|
|
2008-11-03 11:46:57 +01:00
|
|
|
/* stack bottom layers */
|
2008-11-17 09:58:43 +01:00
|
|
|
for(layer = LAYER_BELOW; layer < LAYER_FULLSCREEN; layer++)
|
2008-11-03 11:46:57 +01:00
|
|
|
for(node = last; node; node = node->prev)
|
2008-09-22 19:23:28 +02:00
|
|
|
if(client_layer_translator(node->client) == layer)
|
2008-11-10 12:32:04 +01:00
|
|
|
config_win_vals[0] = client_stack_above(node->client,
|
|
|
|
config_win_vals[0]);
|
2008-09-22 19:23:28 +02:00
|
|
|
|
2008-11-03 11:46:57 +01:00
|
|
|
/* then stack ontop wibox window */
|
2008-09-22 19:23:28 +02:00
|
|
|
for(screen = 0; screen < globalconf.nscreen; screen++)
|
2008-11-03 16:54:13 +01:00
|
|
|
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
2008-09-22 19:23:28 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
|
2008-11-03 11:46:57 +01:00
|
|
|
if(sb->ontop)
|
2008-09-22 19:23:28 +02:00
|
|
|
{
|
|
|
|
xcb_configure_window(globalconf.connection,
|
|
|
|
sb->sw.window,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] = sb->sw.window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-03 11:46:57 +01:00
|
|
|
/* finally stack ontop and fullscreen windows */
|
|
|
|
for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
|
|
|
|
for(node = last; node; node = node->prev)
|
2008-08-21 17:52:44 +02:00
|
|
|
if(client_layer_translator(node->client) == layer)
|
2008-11-10 12:32:04 +01:00
|
|
|
config_win_vals[0] = client_stack_above(node->client,
|
|
|
|
config_win_vals[0]);
|
2008-06-27 22:49:54 +02:00
|
|
|
}
|
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
/** Manage a new client.
|
|
|
|
* \param w The window.
|
|
|
|
* \param wgeom Window geometry.
|
2008-09-03 22:25:24 +02:00
|
|
|
* \param phys_screen Physical screen number.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \param screen Virtual screen number where to manage client.
|
2007-09-20 21:27:43 +02:00
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-09-03 22:25:24 +02:00
|
|
|
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-08-13 02:02:19 +02:00
|
|
|
xcb_get_property_cookie_t ewmh_icon_cookie;
|
2008-09-03 14:59:18 +02:00
|
|
|
client_t *c;
|
2008-09-17 16:38:38 +02:00
|
|
|
image_t *icon;
|
2008-06-30 13:06:23 +02:00
|
|
|
const uint32_t select_input_val[] =
|
|
|
|
{
|
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY
|
|
|
|
| XCB_EVENT_MASK_PROPERTY_CHANGE
|
|
|
|
| XCB_EVENT_MASK_ENTER_WINDOW
|
|
|
|
};
|
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-06-30 13:09:24 +02:00
|
|
|
if(systray_iskdedockapp(w))
|
|
|
|
{
|
2008-09-03 22:25:24 +02:00
|
|
|
systray_request_handle(w, phys_screen, NULL);
|
2008-06-30 13:09:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-07 11:05:21 +01:00
|
|
|
/* Send request to get NET_WM_ICON property as soon as possible... */
|
|
|
|
ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
|
|
|
|
xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
|
2008-04-11 11:35:11 +02:00
|
|
|
c = p_new(client_t, 1);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-09-03 22:37:43 +02:00
|
|
|
c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
|
2008-01-22 09:50:24 +01:00
|
|
|
|
2008-09-03 22:25:24 +02:00
|
|
|
c->phys_screen = phys_screen;
|
2008-03-21 10:53:17 +01:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* Initial values */
|
2007-09-05 20:15:00 +02:00
|
|
|
c->win = w;
|
2008-03-22 14:59:03 +01:00
|
|
|
c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
|
|
|
|
c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
|
|
|
|
c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
|
|
|
|
c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
|
2008-07-30 10:40:21 +02:00
|
|
|
client_setborder(c, wgeom->border_width);
|
2008-09-11 15:26:56 +02:00
|
|
|
if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
|
2008-09-17 16:38:38 +02:00
|
|
|
c->icon = image_ref(&icon);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-09-03 20:22:33 +02:00
|
|
|
/* we honor size hints by default */
|
|
|
|
c->honorsizehints = true;
|
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* update hints */
|
2008-09-16 14:09:56 +02:00
|
|
|
property_update_wm_normal_hints(c, NULL);
|
|
|
|
property_update_wm_hints(c, NULL);
|
2008-09-16 18:07:42 +02:00
|
|
|
property_update_wm_transient_for(c, NULL);
|
|
|
|
|
|
|
|
if(c->transient_for)
|
|
|
|
screen = c->transient_for->screen;
|
2007-12-28 20:48:29 +01:00
|
|
|
|
2008-03-15 14:46:45 +01:00
|
|
|
/* Try to load props if any */
|
2008-09-05 02:05:30 +02:00
|
|
|
client_loadprops(c, &globalconf.screens[screen]);
|
|
|
|
|
2008-03-15 14:46:45 +01:00
|
|
|
|
|
|
|
/* Then check clients hints */
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_check_hints(c);
|
2008-01-13 16:30:43 +01:00
|
|
|
|
2008-11-05 10:24:23 +01:00
|
|
|
/* move client to screen, but do not tag it for now */
|
|
|
|
screen_client_moveto(c, screen, false, true);
|
|
|
|
|
2008-09-05 02:05:30 +02:00
|
|
|
/* Check if client has been tagged by loading props, or maybe with its
|
|
|
|
* hints.
|
|
|
|
* If not, we tag it with current selected ones.
|
|
|
|
* This could be done on Lua side, but it's a sane behaviour. */
|
|
|
|
if(!c->issticky)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
tag_array_t *tags = &globalconf.screens[screen].tags;
|
|
|
|
for(i = 0; i < tags->len; i++)
|
|
|
|
if(is_client_tagged(c, tags->tab[i]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* if no tag, set current selected */
|
|
|
|
if(i == tags->len)
|
|
|
|
for(i = 0; i < tags->len; i++)
|
|
|
|
if(tags->tab[i]->selected)
|
|
|
|
tag_client(c, tags->tab[i]);
|
|
|
|
}
|
|
|
|
|
2008-05-23 22:40:17 +02:00
|
|
|
/* Push client in client list */
|
2008-10-20 15:01:16 +02:00
|
|
|
client_list_push(&globalconf.clients, client_ref(&c));
|
|
|
|
|
2008-05-25 19:47:19 +02:00
|
|
|
/* Push client in stack */
|
2008-06-12 13:12:38 +02:00
|
|
|
client_raise(c);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
/* update window title */
|
2008-09-16 14:09:56 +02:00
|
|
|
property_update_wm_name(c);
|
2008-10-21 15:12:55 +02:00
|
|
|
property_update_wm_icon_name(c);
|
2008-06-05 09:25:38 +02:00
|
|
|
|
2008-09-03 22:15:14 +02:00
|
|
|
/* update strut */
|
2008-09-16 14:09:56 +02:00
|
|
|
ewmh_client_strut_update(c, NULL);
|
2008-09-03 22:15:14 +02:00
|
|
|
|
2008-06-17 23:20:03 +02:00
|
|
|
ewmh_update_net_client_list(c->phys_screen);
|
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/* Always stay in NORMAL_STATE. Even though iconified seems more
|
|
|
|
* appropriate sometimes. The only possible loss is that clients not using
|
|
|
|
* visibility events may continue to proces data (when banned).
|
|
|
|
* Without any exposes or other events the cost should be fairly limited though.
|
|
|
|
*
|
|
|
|
* Some clients may expect the window to be unmapped when STATE_ICONIFIED.
|
|
|
|
* Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
|
|
|
|
*
|
|
|
|
* "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
|
|
|
|
* (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
|
|
|
|
*
|
|
|
|
* "Once a client's window has left the Withdrawn state, the window will be mapped
|
|
|
|
* if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
|
|
|
|
*
|
|
|
|
* At this stage it's just safer to keep it in normal state and avoid confusion.
|
|
|
|
*/
|
|
|
|
window_state_set(c->win, XCB_WM_STATE_NORMAL);
|
|
|
|
|
|
|
|
/* Move window outside the viewport before mapping it. */
|
|
|
|
/* This also sets the state to iconified. */
|
|
|
|
client_ban(c);
|
|
|
|
xcb_map_window(globalconf.connection, c->win);
|
|
|
|
|
2008-10-20 15:01:16 +02:00
|
|
|
/* Call hook to notify list change */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.clients != LUA_REFNIL)
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
2008-10-20 15:01:16 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
/* call hook */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.manage != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, c);
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
|
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Compute client geometry with respect to its geometry hints.
|
|
|
|
* \param c The client.
|
|
|
|
* \param geometry The geometry that the client might receive.
|
2008-06-18 13:58:31 +02:00
|
|
|
* \return The geometry the client must take respecting its hints.
|
2008-06-10 19:29:53 +02:00
|
|
|
*/
|
2008-06-18 13:58:31 +02:00
|
|
|
area_t
|
2008-04-11 11:35:11 +02:00
|
|
|
client_geometry_hints(client_t *c, area_t geometry)
|
2008-03-14 14:27:56 +01:00
|
|
|
{
|
|
|
|
double dx, dy, max, min, ratio;
|
|
|
|
|
|
|
|
if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
|
|
|
|
&& (geometry.width - c->basew) > 0)
|
|
|
|
{
|
|
|
|
dx = (double) (geometry.width - c->basew);
|
|
|
|
dy = (double) (geometry.height - c->baseh);
|
|
|
|
min = (double) (c->minax) / (double) (c->minay);
|
|
|
|
max = (double) (c->maxax) / (double) (c->maxay);
|
|
|
|
ratio = dx / dy;
|
|
|
|
if(max > 0 && min > 0 && ratio > 0)
|
|
|
|
{
|
|
|
|
if(ratio < min)
|
|
|
|
{
|
|
|
|
dy = (dx * min + dy) / (min * min + 1);
|
|
|
|
dx = dy * min;
|
|
|
|
geometry.width = (int) dx + c->basew;
|
|
|
|
geometry.height = (int) dy + c->baseh;
|
|
|
|
}
|
|
|
|
else if(ratio > max)
|
|
|
|
{
|
|
|
|
dy = (dx * min + dy) / (max * max + 1);
|
|
|
|
dx = dy * min;
|
|
|
|
geometry.width = (int) dx + c->basew;
|
|
|
|
geometry.height = (int) dy + c->baseh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c->minw && geometry.width < c->minw)
|
|
|
|
geometry.width = c->minw;
|
|
|
|
if(c->minh && geometry.height < c->minh)
|
|
|
|
geometry.height = c->minh;
|
|
|
|
if(c->maxw && geometry.width > c->maxw)
|
|
|
|
geometry.width = c->maxw;
|
|
|
|
if(c->maxh && geometry.height > c->maxh)
|
|
|
|
geometry.height = c->maxh;
|
|
|
|
if(c->incw)
|
|
|
|
geometry.width -= (geometry.width - c->basew) % c->incw;
|
|
|
|
if(c->inch)
|
|
|
|
geometry.height -= (geometry.height - c->baseh) % c->inch;
|
|
|
|
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
2008-05-27 20:17:33 +02:00
|
|
|
/** Resize client window.
|
|
|
|
* \param c Client to resize.
|
|
|
|
* \param geometry New window geometry.
|
|
|
|
* \param hints Use size hints.
|
2007-12-30 15:08:38 +01:00
|
|
|
*/
|
2008-09-22 17:45:07 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_resize(client_t *c, area_t geometry, bool hints)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
int new_screen;
|
|
|
|
area_t area;
|
|
|
|
layout_t *layout = layout_get_current(c->screen);
|
2008-06-03 18:41:54 +02:00
|
|
|
|
2008-11-14 16:16:09 +01:00
|
|
|
if(c->titlebar && c->titlebar->isvisible && !client_isfloating(c) && layout != layout_floating)
|
2008-06-18 17:05:10 +02:00
|
|
|
geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
|
2008-03-26 10:57:06 +01:00
|
|
|
|
2008-03-16 10:01:55 +01:00
|
|
|
if(hints)
|
|
|
|
geometry = client_geometry_hints(c, geometry);
|
|
|
|
|
2008-01-05 20:18:30 +01:00
|
|
|
if(geometry.width <= 0 || geometry.height <= 0)
|
2008-09-22 17:45:07 +02:00
|
|
|
return;
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
/* offscreen appearance fixes */
|
|
|
|
area = display_area_get(c->phys_screen, NULL,
|
|
|
|
&globalconf.screens[c->screen].padding);
|
|
|
|
|
|
|
|
if(geometry.x > area.width)
|
|
|
|
geometry.x = area.width - geometry.width - 2 * c->border;
|
|
|
|
if(geometry.y > area.height)
|
|
|
|
geometry.y = area.height - geometry.height - 2 * c->border;
|
|
|
|
if(geometry.x + geometry.width + 2 * c->border < 0)
|
|
|
|
geometry.x = 0;
|
|
|
|
if(geometry.y + geometry.height + 2 * c->border < 0)
|
|
|
|
geometry.y = 0;
|
|
|
|
|
2008-11-10 12:10:06 +01:00
|
|
|
if(c->geometry.x != geometry.x
|
|
|
|
|| c->geometry.y != geometry.y
|
|
|
|
|| c->geometry.width != geometry.width
|
|
|
|
|| c->geometry.height != geometry.height)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-09-03 22:37:43 +02:00
|
|
|
new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-11-15 14:09:41 +01:00
|
|
|
/* Values to configure a window is an array where values are
|
|
|
|
* stored according to 'value_mask' */
|
|
|
|
uint32_t values[4];
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
c->geometry.x = values[0] = geometry.x;
|
|
|
|
c->geometry.y = values[1] = geometry.y;
|
2008-11-15 14:09:41 +01:00
|
|
|
c->geometry.width = values[2] = geometry.width;
|
2008-03-21 16:50:17 +01:00
|
|
|
c->geometry.height = values[3] = geometry.height;
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2008-01-11 17:54:48 +01:00
|
|
|
/* save the floating geometry if the window is floating but not
|
|
|
|
* maximized */
|
2008-11-14 16:16:09 +01:00
|
|
|
if(client_isfloating(c)
|
2008-11-15 14:15:45 +01:00
|
|
|
|| layout_get_current(new_screen) == layout_floating
|
|
|
|
|| layout_get_current(c->screen) == layout_floating)
|
2008-08-21 17:52:44 +02:00
|
|
|
if(!c->isfullscreen)
|
2008-05-25 17:42:20 +02:00
|
|
|
c->f_geometry = geometry;
|
2008-09-24 12:13:21 +02:00
|
|
|
|
|
|
|
titlebar_update_geometry_floating(c);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/* The idea is to give a client a resize even when banned. */
|
|
|
|
/* We just have to move the (x,y) to keep it out of the viewport. */
|
|
|
|
/* This at least doesn't break expectations about events. */
|
|
|
|
if (c->isbanned)
|
|
|
|
{
|
|
|
|
geometry.x = values[0] = - (geometry.width + 2 * c->border);
|
|
|
|
geometry.y = values[1] = - (geometry.height + 2 * c->border);
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
2008-11-15 14:09:41 +01:00
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
|
|
|
|
| XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
2008-03-21 16:50:17 +01:00
|
|
|
values);
|
2008-01-06 14:40:23 +01:00
|
|
|
window_configure(c->win, geometry, c->border);
|
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
if(c->screen != new_screen)
|
2008-09-05 02:05:30 +02:00
|
|
|
screen_client_moveto(c, new_screen, true, false);
|
2008-03-26 11:03:52 +01:00
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "geometry");
|
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-11-17 18:49:11 +01:00
|
|
|
/** Set a client floating.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \param c The client.
|
|
|
|
* \param floating Set floating, or not.
|
|
|
|
* \param layer Layer to put the floating window onto.
|
|
|
|
*/
|
2008-01-17 10:40:39 +01:00
|
|
|
void
|
2008-06-25 22:26:53 +02:00
|
|
|
client_setfloating(client_t *c, bool floating)
|
2008-01-17 10:40:39 +01:00
|
|
|
{
|
2008-09-07 23:55:38 +02:00
|
|
|
if(c->isfloating != floating
|
|
|
|
&& (c->type == WINDOW_TYPE_NORMAL))
|
2008-01-17 19:17:53 +01:00
|
|
|
{
|
2008-01-17 10:40:39 +01:00
|
|
|
if((c->isfloating = floating))
|
2008-08-21 17:52:44 +02:00
|
|
|
if(!c->isfullscreen)
|
|
|
|
client_resize(c, c->f_geometry, false);
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(c);
|
2008-08-21 17:52:44 +02:00
|
|
|
client_stack();
|
2008-08-25 16:38:45 +02:00
|
|
|
xcb_change_property(globalconf.connection,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
|
|
|
|
&c->isfloating);
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "floating");
|
2008-01-17 19:17:53 +01:00
|
|
|
}
|
2008-01-17 10:40:39 +01:00
|
|
|
}
|
|
|
|
|
2008-09-18 13:51:10 +02:00
|
|
|
/** Set a client minimized, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client minimized.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setminimized(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->isminimized != s)
|
|
|
|
{
|
|
|
|
client_need_arrange(c);
|
|
|
|
c->isminimized = s;
|
|
|
|
client_need_arrange(c);
|
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "minimized");
|
2008-09-18 13:51:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-21 16:29:53 +02:00
|
|
|
/** Set a client sticky, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client sticky.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setsticky(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->issticky != s)
|
|
|
|
{
|
|
|
|
client_need_arrange(c);
|
|
|
|
c->issticky = s;
|
|
|
|
client_need_arrange(c);
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
hooks_property(c, "sticky");
|
2008-08-21 16:29:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-21 17:52:44 +02:00
|
|
|
/** Set a client fullscreen, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client fullscreen.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setfullscreen(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->isfullscreen != s)
|
|
|
|
{
|
|
|
|
area_t geometry;
|
|
|
|
|
|
|
|
/* become fullscreen! */
|
|
|
|
if((c->isfullscreen = s))
|
|
|
|
{
|
2008-11-03 19:48:33 +01:00
|
|
|
geometry = screen_area_get(c->screen, NULL, NULL, false);
|
2008-08-21 17:52:44 +02:00
|
|
|
c->m_geometry = c->geometry;
|
|
|
|
c->oldborder = c->border;
|
|
|
|
client_setborder(c, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
geometry = c->m_geometry;
|
|
|
|
client_setborder(c, c->oldborder);
|
|
|
|
}
|
|
|
|
client_resize(c, geometry, false);
|
|
|
|
client_need_arrange(c);
|
|
|
|
client_stack();
|
2008-08-25 16:38:45 +02:00
|
|
|
xcb_change_property(globalconf.connection,
|
|
|
|
XCB_PROP_MODE_REPLACE,
|
|
|
|
c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
|
|
|
|
&c->isfullscreen);
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
hooks_property(c, "fullscreen");
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a client above, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client above.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setabove(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->isabove != s)
|
|
|
|
{
|
|
|
|
c->isabove = s;
|
|
|
|
client_stack();
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "above");
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a client below, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client below.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setbelow(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->isbelow != s)
|
|
|
|
{
|
|
|
|
c->isbelow = s;
|
|
|
|
client_stack();
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "below");
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a client modal, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client moda.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setmodal(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->ismodal != s)
|
|
|
|
{
|
|
|
|
c->ismodal = s;
|
|
|
|
client_stack();
|
2008-09-18 13:51:10 +02:00
|
|
|
ewmh_client_update_hints(c);
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "modal");
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Set a client ontop, or not.
|
|
|
|
* \param c The client.
|
|
|
|
* \param s Set or not the client moda.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
client_setontop(client_t *c, bool s)
|
|
|
|
{
|
|
|
|
if(c->isontop != s)
|
|
|
|
{
|
|
|
|
c->isontop = s;
|
|
|
|
client_stack();
|
2008-09-22 17:54:48 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(c, "ontop");
|
2008-08-21 17:52:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
/** Save client properties as an X property.
|
|
|
|
* \param c The client.
|
2007-12-30 15:08:38 +01:00
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-08-25 16:38:45 +02:00
|
|
|
client_saveprops_tags(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-23 17:37:19 +02:00
|
|
|
tag_array_t *tags = &globalconf.screens[c->screen].tags;
|
2008-08-25 16:38:45 +02:00
|
|
|
unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
|
2008-06-23 17:37:19 +02:00
|
|
|
int i;
|
2008-06-05 09:25:38 +02:00
|
|
|
|
2008-06-23 17:37:19 +02:00
|
|
|
for(i = 0; i < tags->len; i++)
|
|
|
|
prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
|
2007-09-06 22:02:50 +02:00
|
|
|
|
2008-08-25 16:38:45 +02:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-11-20 22:11:13 +01:00
|
|
|
/** Unban a client and move it back into the viewport.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \param c The client.
|
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_unban(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-11-20 22:11:13 +01:00
|
|
|
if(c->isbanned)
|
2008-09-20 11:28:50 +02:00
|
|
|
{
|
2008-11-20 22:11:13 +01:00
|
|
|
/* Move the client back where it belongs. */
|
|
|
|
uint32_t request[2] = { c->geometry.x, c->geometry.y };
|
|
|
|
|
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
request);
|
|
|
|
window_configure(c->win, c->geometry, c->border);
|
|
|
|
|
|
|
|
/* Do this manually because the system doesn't know we moved the toolbar.
|
|
|
|
* Note that !isvisible titlebars are unmapped and for fullscreen it'll
|
|
|
|
* end up offscreen anyway. */
|
|
|
|
if(c->titlebar)
|
|
|
|
{
|
|
|
|
simple_window_t *sw = &c->titlebar->sw;
|
|
|
|
/* All resizing is done, so only move now. */
|
|
|
|
request[0] = sw->geometry.x;
|
|
|
|
request[1] = sw->geometry.y;
|
|
|
|
|
|
|
|
xcb_configure_window(globalconf.connection, sw->window,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
|
|
|
|
request);
|
|
|
|
}
|
|
|
|
|
|
|
|
c->isbanned = false;
|
2008-09-20 11:28:50 +02:00
|
|
|
}
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Unmanage a client.
|
|
|
|
* \param c The client.
|
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_unmanage(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-06-23 17:37:19 +02:00
|
|
|
tag_array_t *tags = &globalconf.screens[c->screen].tags;
|
2008-06-09 21:43:09 +02:00
|
|
|
|
2008-09-06 09:18:23 +02:00
|
|
|
if(globalconf.screens[c->phys_screen].client_focus == c)
|
2008-07-31 17:29:05 +02:00
|
|
|
client_unfocus(c);
|
|
|
|
|
2008-10-20 15:01:16 +02:00
|
|
|
/* remove client everywhere */
|
|
|
|
client_list_detach(&globalconf.clients, c);
|
|
|
|
stack_client_delete(c);
|
|
|
|
for(int i = 0; i < tags->len; i++)
|
|
|
|
untag_client(c, tags->tab[i]);
|
|
|
|
|
2008-06-10 19:03:10 +02:00
|
|
|
/* call hook */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.unmanage != LUA_REFNIL)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, c);
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
|
|
|
|
}
|
2008-06-10 19:03:10 +02:00
|
|
|
|
2008-10-20 15:01:16 +02:00
|
|
|
/* Call hook to notify list change */
|
2008-11-20 17:48:23 +01:00
|
|
|
if(globalconf.hooks.clients != LUA_REFNIL)
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
|
2008-10-20 15:01:16 +02:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
/* The server grab construct avoids race conditions. */
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_grab_server(globalconf.connection);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
|
|
|
(uint32_t *) &c->oldborder);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-08-11 13:27:28 +02:00
|
|
|
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
|
2008-08-19 10:59:40 +02:00
|
|
|
XCB_BUTTON_MASK_ANY);
|
2008-09-09 16:14:36 +02:00
|
|
|
window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-08-26 19:39:12 +02:00
|
|
|
xcb_flush(globalconf.connection);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_ungrab_server(globalconf.connection);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-09-24 12:13:21 +02:00
|
|
|
titlebar_client_detach(c);
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2008-06-17 23:20:03 +02:00
|
|
|
ewmh_update_net_client_list(c->phys_screen);
|
|
|
|
|
2008-06-28 11:46:51 +02:00
|
|
|
/* delete properties */
|
2008-08-25 16:38:45 +02:00
|
|
|
xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
|
|
|
|
xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
|
2008-06-28 11:46:51 +02:00
|
|
|
|
2008-09-03 22:15:14 +02:00
|
|
|
if(client_hasstrut(c))
|
2008-09-24 12:13:21 +02:00
|
|
|
/* All the wiboxes (may) need to be repositioned */
|
2008-09-18 16:03:05 +02:00
|
|
|
for(int screen = 0; screen < globalconf.nscreen; screen++)
|
2008-09-24 12:13:21 +02:00
|
|
|
for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
|
2008-09-20 16:45:43 +02:00
|
|
|
{
|
2008-09-24 12:13:21 +02:00
|
|
|
wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
|
|
|
|
wibox_position_update(s);
|
2008-09-20 16:45:43 +02:00
|
|
|
}
|
2008-09-03 22:15:14 +02:00
|
|
|
|
2008-07-31 17:29:05 +02:00
|
|
|
/* set client as invalid */
|
|
|
|
c->invalid = true;
|
|
|
|
|
|
|
|
client_unref(&c);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-10-11 09:38:48 +02:00
|
|
|
/** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
|
2008-03-31 20:07:13 +02:00
|
|
|
* supported.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \param c The client to kill.
|
2008-03-31 20:07:13 +02:00
|
|
|
*/
|
2007-10-01 20:42:59 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_kill(client_t *c)
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
2008-10-11 09:38:48 +02:00
|
|
|
if(window_hasproto(c->win, WM_DELETE_WINDOW))
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
2008-10-11 09:38:48 +02:00
|
|
|
xcb_client_message_event_t ev;
|
|
|
|
|
2008-03-28 14:48:05 +01:00
|
|
|
/* Initialize all of event's fields first */
|
2008-06-05 09:25:38 +02:00
|
|
|
p_clear(&ev, 1);
|
2008-03-28 14:48:05 +01:00
|
|
|
|
|
|
|
ev.response_type = XCB_CLIENT_MESSAGE;
|
2008-03-21 16:50:17 +01:00
|
|
|
ev.window = c->win;
|
2008-03-28 14:48:05 +01:00
|
|
|
ev.format = 32;
|
2008-03-21 16:50:17 +01:00
|
|
|
ev.data.data32[1] = XCB_CURRENT_TIME;
|
2008-06-30 18:55:14 +02:00
|
|
|
ev.type = WM_PROTOCOLS;
|
|
|
|
ev.data.data32[0] = WM_DELETE_WINDOW;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
xcb_send_event(globalconf.connection, false, c->win,
|
|
|
|
XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
|
|
|
else
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_kill_client(globalconf.connection, c->win);
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2008-06-05 09:25:38 +02:00
|
|
|
/** Get all clients into a table.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-09-18 15:07:34 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \luastack
|
2008-09-18 15:11:18 +02:00
|
|
|
* \lparam An optional screen nunmber.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \lreturn A table with all clients.
|
2008-06-05 09:25:38 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_client_get(lua_State *L)
|
2007-12-27 20:49:38 +01:00
|
|
|
{
|
2008-09-18 15:11:18 +02:00
|
|
|
int i = 1, screen;
|
2008-05-23 22:49:39 +02:00
|
|
|
client_t *c;
|
2007-12-27 20:49:38 +01:00
|
|
|
|
2008-09-18 15:11:18 +02:00
|
|
|
screen = luaL_optnumber(L, 1, 0) - 1;
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
|
2008-09-18 15:11:18 +02:00
|
|
|
if(screen == SCREEN_UNDEF)
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, c);
|
|
|
|
lua_rawseti(L, -2, i++);
|
|
|
|
}
|
|
|
|
else
|
2008-05-23 13:17:02 +02:00
|
|
|
{
|
2008-09-18 15:11:18 +02:00
|
|
|
luaA_checkscreen(screen);
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(c->screen == screen)
|
|
|
|
{
|
|
|
|
luaA_client_userdata_new(globalconf.L, c);
|
|
|
|
lua_rawseti(L, -2, i++);
|
|
|
|
}
|
2008-05-23 13:17:02 +02:00
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return 1;
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
|
2008-09-18 15:07:34 +02:00
|
|
|
/** Check if a client is visible on its screen.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
|
|
|
* \lreturn A boolean value, true if the client is visible, false otherwise.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_isvisible(lua_State *L)
|
|
|
|
{
|
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-28 14:33:45 +02:00
|
|
|
/** Set client border width.
|
2008-06-05 09:25:38 +02:00
|
|
|
* \param c The client.
|
|
|
|
* \param width The border width.
|
2008-05-28 14:33:45 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-06-11 08:12:38 +02:00
|
|
|
client_setborder(client_t *c, int width)
|
2008-05-28 14:33:45 +02:00
|
|
|
{
|
2008-06-11 08:12:38 +02:00
|
|
|
uint32_t w = width;
|
|
|
|
|
2008-09-03 14:59:18 +02:00
|
|
|
if(width > 0 && (c->type == WINDOW_TYPE_DOCK
|
|
|
|
|| c->type == WINDOW_TYPE_SPLASH
|
|
|
|
|| c->type == WINDOW_TYPE_DESKTOP
|
|
|
|
|| c->isfullscreen))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(width == c->border || width < 0)
|
2008-05-28 14:33:45 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
c->border = width;
|
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
2008-06-11 08:12:38 +02:00
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
|
2008-07-30 10:04:03 +02:00
|
|
|
|
2008-08-21 15:36:54 +02:00
|
|
|
if(client_isvisible(c, c->screen))
|
|
|
|
{
|
2008-09-03 14:59:18 +02:00
|
|
|
if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
|
2008-08-21 15:36:54 +02:00
|
|
|
titlebar_update_geometry_floating(c);
|
|
|
|
else
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
}
|
2008-09-22 17:54:48 +02:00
|
|
|
|
|
|
|
hooks_property(c, "border_width");
|
2008-05-28 14:33:45 +02:00
|
|
|
}
|
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Kill a client.
|
|
|
|
* \param L The Lua VM state.
|
2008-06-11 02:46:30 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
2008-06-10 19:29:53 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_client_kill(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-05-20 15:39:47 +02:00
|
|
|
client_kill(*c);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-06 08:49:31 +01:00
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Swap a client with another one.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \luastack
|
2008-06-11 02:46:30 +02:00
|
|
|
* \lvalue A client.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \lparam A client to swap with.
|
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_client_swap(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
client_t **swap = luaA_checkudata(L, 2, "client");
|
2008-10-20 15:01:16 +02:00
|
|
|
|
2008-11-14 10:36:15 +01:00
|
|
|
if(*c != *swap)
|
|
|
|
{
|
|
|
|
client_list_swap(&globalconf.clients, *swap, *c);
|
|
|
|
client_need_arrange(*c);
|
|
|
|
client_need_arrange(*swap);
|
|
|
|
|
|
|
|
/* Call hook to notify list change */
|
|
|
|
if(globalconf.hooks.clients != LUA_REFNIL)
|
|
|
|
luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
|
|
|
|
}
|
2008-10-20 15:01:16 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
2008-02-06 08:49:31 +01:00
|
|
|
}
|
|
|
|
|
2008-08-13 17:49:57 +02:00
|
|
|
/** Access or set the client tags.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \lparam A table with tags to set, or none to get the current tags table.
|
|
|
|
* \return The clients tag.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_tags(lua_State *L)
|
|
|
|
{
|
|
|
|
tag_array_t *tags;
|
|
|
|
tag_t **tag;
|
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-08-17 07:52:04 +02:00
|
|
|
int j = 0;
|
2008-08-13 17:49:57 +02:00
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
tags = &globalconf.screens[(*c)->screen].tags;
|
|
|
|
for(int i = 0; i < tags->len; i++)
|
|
|
|
untag_client(*c, tags->tab[i]);
|
|
|
|
lua_pushnil(L);
|
|
|
|
while(lua_next(L, 2))
|
|
|
|
{
|
|
|
|
tag = luaA_checkudata(L, -1, "tag");
|
|
|
|
tag_client(*c, *tag);
|
|
|
|
lua_pop(L, 1);
|
|
|
|
}
|
2008-08-17 07:52:04 +02:00
|
|
|
lua_pop(L, 1);
|
2008-08-13 17:49:57 +02:00
|
|
|
}
|
2008-08-17 07:52:04 +02:00
|
|
|
|
|
|
|
tags = &globalconf.screens[(*c)->screen].tags;
|
2008-12-04 16:55:40 +01:00
|
|
|
luaA_otable_new(L);
|
2008-08-17 07:52:04 +02:00
|
|
|
for(int i = 0; i < tags->len; i++)
|
|
|
|
if(is_client_tagged(*c, tags->tab[i]))
|
|
|
|
{
|
|
|
|
luaA_tag_userdata_new(L, tags->tab[i]);
|
|
|
|
lua_rawseti(L, -2, ++j);
|
|
|
|
}
|
2008-08-13 17:49:57 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-05-26 16:17:57 +02:00
|
|
|
/** Raise a client on top of others which are on the same layer.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-06-11 02:46:30 +02:00
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
2008-05-26 16:17:57 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_raise(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-05-26 16:17:57 +02:00
|
|
|
client_raise(*c);
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-11 18:41:04 +02:00
|
|
|
|
2008-11-12 11:27:58 +01:00
|
|
|
/** Lower a client on bottom of others which are on the same layer.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_lower(lua_State *L)
|
|
|
|
{
|
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
client_lower(*c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-10 19:29:53 +02:00
|
|
|
/** Redraw a client by unmapping and mapping it quickly.
|
|
|
|
* \param L The Lua VM state.
|
2008-06-11 02:46:30 +02:00
|
|
|
*
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
2008-06-10 19:29:53 +02:00
|
|
|
*/
|
2008-05-20 15:39:47 +02:00
|
|
|
static int
|
|
|
|
luaA_client_redraw(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-08-20 23:57:27 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
xcb_unmap_window(globalconf.connection, (*c)->win);
|
|
|
|
xcb_map_window(globalconf.connection, (*c)->win);
|
2008-08-20 23:57:27 +02:00
|
|
|
|
|
|
|
/* Set the focus on the current window if the redraw has been
|
|
|
|
performed on the window where the pointer is currently on
|
|
|
|
because after the unmapping/mapping, the focus is lost */
|
|
|
|
if(globalconf.screen_focus->client_focus == *c)
|
|
|
|
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
|
|
(*c)->win, XCB_CURRENT_TIME);
|
2008-08-21 08:12:28 +02:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-02 08:31:54 +02:00
|
|
|
/** Stop managing a client.
|
2008-06-10 19:29:53 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-08-26 16:03:01 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-06-11 02:46:30 +02:00
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
2008-06-02 08:31:54 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_unmanage(lua_State *L)
|
|
|
|
{
|
2008-06-04 18:27:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
2008-06-02 08:31:54 +02:00
|
|
|
client_unmanage(*c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-21 15:31:52 +02:00
|
|
|
/** Return client geometry.
|
2008-08-26 16:03:01 +02:00
|
|
|
* \param L The Lua VM state.
|
2008-11-14 20:25:10 +01:00
|
|
|
* \param full Use titlebar also.
|
2008-08-26 16:03:01 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
2008-08-20 12:00:22 +02:00
|
|
|
static int
|
2008-11-14 20:25:10 +01:00
|
|
|
luaA_client_handlegeom(lua_State *L, bool full)
|
2008-08-20 12:00:22 +02:00
|
|
|
{
|
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
2008-11-10 12:10:06 +01:00
|
|
|
if(client_isfloating(*c)
|
|
|
|
|| layout_get_current((*c)->screen) == layout_floating)
|
2008-08-20 12:00:22 +02:00
|
|
|
{
|
|
|
|
area_t geometry;
|
|
|
|
|
|
|
|
luaA_checktable(L, 2);
|
|
|
|
geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
|
|
|
|
geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
|
2008-11-10 12:10:06 +01:00
|
|
|
if(client_isfixed(*c))
|
|
|
|
{
|
|
|
|
geometry.width = (*c)->geometry.width;
|
|
|
|
geometry.height = (*c)->geometry.height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
|
|
|
|
geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
|
|
|
|
}
|
2008-11-14 20:25:10 +01:00
|
|
|
if(full)
|
|
|
|
geometry = titlebar_geometry_remove((*c)->titlebar,
|
|
|
|
(*c)->border,
|
|
|
|
geometry);
|
2008-11-17 16:25:26 +01:00
|
|
|
client_resize(*c, geometry, (*c)->honorsizehints);
|
2008-08-20 12:00:22 +02:00
|
|
|
}
|
|
|
|
|
2008-11-14 20:25:10 +01:00
|
|
|
if(full)
|
|
|
|
return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
|
|
|
|
(*c)->border,
|
|
|
|
(*c)->geometry));
|
|
|
|
|
2008-08-20 12:00:22 +02:00
|
|
|
return luaA_pusharea(L, (*c)->geometry);
|
|
|
|
}
|
|
|
|
|
2008-11-14 20:25:10 +01:00
|
|
|
/** Return client geometry.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A table with new coordinates, or none.
|
|
|
|
* \lreturn A table with client coordinates.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_geometry(lua_State *L)
|
|
|
|
{
|
|
|
|
return luaA_client_handlegeom(L, false);
|
|
|
|
}
|
|
|
|
|
2008-10-21 15:31:52 +02:00
|
|
|
/** Return client geometry, using also titlebar and border width.
|
2008-08-26 16:03:01 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lparam A table with new coordinates, or none.
|
|
|
|
* \lreturn A table with client coordinates.
|
|
|
|
*/
|
|
|
|
static int
|
2008-10-21 15:31:52 +02:00
|
|
|
luaA_client_fullgeometry(lua_State *L)
|
2008-08-26 16:03:01 +02:00
|
|
|
{
|
2008-11-14 20:25:10 +01:00
|
|
|
return luaA_client_handlegeom(L, true);
|
2008-08-26 16:03:01 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 19:37:10 +02:00
|
|
|
/** Client newindex.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
2008-07-08 10:54:57 +02:00
|
|
|
int
|
2008-07-01 19:37:10 +02:00
|
|
|
luaA_client_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
const char *buf = luaL_checklstring(L, 2, &len);
|
2008-07-01 19:43:23 +02:00
|
|
|
bool b;
|
2008-07-01 19:52:25 +02:00
|
|
|
double d;
|
2008-07-01 21:39:00 +02:00
|
|
|
int i;
|
2008-09-21 10:13:21 +02:00
|
|
|
wibox_t **t = NULL;
|
2008-09-11 15:26:56 +02:00
|
|
|
image_t **image;
|
2008-07-01 19:37:10 +02:00
|
|
|
|
2008-07-31 17:29:05 +02:00
|
|
|
if((*c)->invalid)
|
|
|
|
luaL_error(L, "client is invalid\n");
|
|
|
|
|
2008-07-01 19:37:10 +02:00
|
|
|
switch(a_tokenize(buf, len))
|
|
|
|
{
|
2008-07-01 21:39:00 +02:00
|
|
|
case A_TK_SCREEN:
|
2008-09-18 16:03:05 +02:00
|
|
|
if(globalconf.xinerama_is_active)
|
2008-08-10 10:32:59 +02:00
|
|
|
{
|
|
|
|
i = luaL_checknumber(L, 3) - 1;
|
|
|
|
luaA_checkscreen(i);
|
|
|
|
if(i != (*c)->screen)
|
2008-09-05 02:05:30 +02:00
|
|
|
screen_client_moveto(*c, i, true, true);
|
2008-08-10 10:32:59 +02:00
|
|
|
}
|
2008-07-01 21:39:00 +02:00
|
|
|
break;
|
2008-07-01 19:43:23 +02:00
|
|
|
case A_TK_HIDE:
|
|
|
|
b = luaA_checkboolean(L, 3);
|
|
|
|
if(b != (*c)->ishidden)
|
|
|
|
{
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(*c);
|
2008-07-01 19:43:23 +02:00
|
|
|
(*c)->ishidden = b;
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(*c);
|
2008-07-01 19:43:23 +02:00
|
|
|
}
|
2008-07-01 19:37:10 +02:00
|
|
|
break;
|
2008-09-06 13:52:05 +02:00
|
|
|
case A_TK_MINIMIZE:
|
2008-09-18 13:51:10 +02:00
|
|
|
client_setminimized(*c, luaA_checkboolean(L, 3));
|
2008-09-06 13:52:05 +02:00
|
|
|
break;
|
2008-08-21 17:58:08 +02:00
|
|
|
case A_TK_FULLSCREEN:
|
|
|
|
client_setfullscreen(*c, luaA_checkboolean(L, 3));
|
|
|
|
break;
|
2008-09-11 15:26:56 +02:00
|
|
|
case A_TK_ICON:
|
|
|
|
image = luaA_checkudata(L, 3, "image");
|
|
|
|
image_unref(&(*c)->icon);
|
|
|
|
image_ref(image);
|
|
|
|
(*c)->icon = *image;
|
2008-10-19 19:14:55 +02:00
|
|
|
/* execute hook */
|
|
|
|
hooks_property(*c, "icon");
|
2008-07-01 19:37:10 +02:00
|
|
|
break;
|
2008-07-01 19:52:25 +02:00
|
|
|
case A_TK_OPACITY:
|
2008-08-15 02:00:58 +02:00
|
|
|
if(lua_isnil(L, 3))
|
|
|
|
window_opacity_set((*c)->win, -1);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d = luaL_checknumber(L, 3);
|
|
|
|
if(d >= 0 && d <= 1)
|
|
|
|
window_opacity_set((*c)->win, d);
|
|
|
|
}
|
2008-07-01 19:52:25 +02:00
|
|
|
break;
|
2008-07-01 19:55:18 +02:00
|
|
|
case A_TK_FLOATING:
|
|
|
|
client_setfloating(*c, luaA_checkboolean(L, 3));
|
|
|
|
break;
|
2008-08-21 16:29:53 +02:00
|
|
|
case A_TK_STICKY:
|
|
|
|
client_setsticky(*c, luaA_checkboolean(L, 3));
|
|
|
|
break;
|
2008-07-01 19:59:36 +02:00
|
|
|
case A_TK_HONORSIZEHINTS:
|
2008-07-01 20:07:21 +02:00
|
|
|
(*c)->honorsizehints = luaA_checkboolean(L, 3);
|
2008-08-21 15:36:54 +02:00
|
|
|
client_need_arrange(*c);
|
2008-07-01 19:59:36 +02:00
|
|
|
break;
|
2008-07-01 20:07:21 +02:00
|
|
|
case A_TK_BORDER_WIDTH:
|
|
|
|
client_setborder(*c, luaL_checknumber(L, 3));
|
|
|
|
break;
|
2008-08-21 17:52:44 +02:00
|
|
|
case A_TK_ONTOP:
|
|
|
|
client_setontop(*c, luaA_checkboolean(L, 3));
|
|
|
|
break;
|
2008-07-01 20:07:21 +02:00
|
|
|
case A_TK_BORDER_COLOR:
|
2008-07-10 15:30:16 +02:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len))
|
2008-09-11 14:11:13 +02:00
|
|
|
&& xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
|
Streamline xcolor_t.
Do not have a ->name char * field, but a char[32] instead. This isn't a
big problem, the longest color in /etc/X11/rgb.txt is 23 chars long, and
if it becomes a problem one day, one could just strip the name and
generate an hexadecimal representation on the fly instead. But allocating
the name is asking for a lot of trouble.
Since we do not allocate anything anymore, just don't allocate anything
anymore at all, it avoids the mess of xcolor_copy/_wipe and fixes a lot of
sleeping bugs (p_dup were used e.g., which is wrong).
Pass xcolor_t *, xcolor_t becomes too big to be passed by value. Add
consts at some places.
xcolor_new allocates nothing, hence is renamed xcolor_init, has xcolor_t
as a first argument (OO-style, this is self), and doesn't touch the
structure at all if it returns false, which allow us to skip a lot of
intermediates values.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Julien Danjou <julien@danjou.info>
2008-07-02 10:14:42 +02:00
|
|
|
xcb_change_window_attributes(globalconf.connection, (*c)->win,
|
|
|
|
XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
|
2008-07-01 20:07:21 +02:00
|
|
|
break;
|
2008-07-01 22:19:23 +02:00
|
|
|
case A_TK_TITLEBAR:
|
2008-09-21 20:39:23 +02:00
|
|
|
if(lua_isnil(L, 3))
|
|
|
|
titlebar_client_detach(*c);
|
|
|
|
else
|
2008-07-01 22:19:23 +02:00
|
|
|
{
|
2008-09-21 20:39:23 +02:00
|
|
|
t = luaA_checkudata(L, 3, "wibox");
|
|
|
|
titlebar_client_attach(*c, *t);
|
2008-07-01 22:19:23 +02:00
|
|
|
}
|
2008-08-07 16:37:58 +02:00
|
|
|
break;
|
2008-07-01 19:49:14 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
2008-07-01 19:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Client object.
|
2008-07-01 19:37:10 +02:00
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \luastack
|
|
|
|
* \lfield name The client title.
|
2008-10-20 17:27:18 +02:00
|
|
|
* \lfield skip_taskbar True if the client does not want to be in taskbar.
|
2008-09-03 15:11:06 +02:00
|
|
|
* \lfield type The window type (desktop, normal, dock, …).
|
2008-07-26 08:45:35 +02:00
|
|
|
* \lfield class The client class.
|
|
|
|
* \lfield instance The client instance.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \lfield pid The client PID, if available.
|
2008-08-28 11:29:21 +02:00
|
|
|
* \lfield role The window role, if available.
|
2008-08-11 11:09:44 +02:00
|
|
|
* \lfield machine The machine client is running on.
|
2008-08-11 11:41:42 +02:00
|
|
|
* \lfield icon_name The client name when iconified.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \lfield screen Client screen number.
|
2008-10-20 17:27:18 +02:00
|
|
|
* \lfield hide Define if the client must be hidden, i.e. never mapped,
|
2008-09-06 13:52:05 +02:00
|
|
|
* invisible in taskbar.
|
|
|
|
* \lfield minimize Define it the client must be iconify, i.e. only visible in
|
|
|
|
* taskbar.
|
2008-07-10 09:22:23 +02:00
|
|
|
* \lfield icon_path Path to the icon used to identify.
|
|
|
|
* \lfield floating True always floating.
|
|
|
|
* \lfield honorsizehints Honor size hints, i.e. respect size ratio.
|
|
|
|
* \lfield border_width The client border width.
|
|
|
|
* \lfield border_color The client border color.
|
|
|
|
* \lfield titlebar The client titlebar.
|
2008-07-29 14:37:17 +02:00
|
|
|
* \lfield urgent The client urgent state.
|
2008-08-12 12:08:20 +02:00
|
|
|
* \lfield focus The focused client.
|
2008-08-15 02:00:58 +02:00
|
|
|
* \lfield opacity The client opacity between 0 and 1.
|
2008-08-21 17:52:44 +02:00
|
|
|
* \lfield ontop The client is on top of every other windows.
|
2008-08-21 17:58:08 +02:00
|
|
|
* \lfield fullscreen The client is fullscreen or not.
|
2008-11-10 15:43:04 +01:00
|
|
|
* \lfield transient_for Return the client the window is transient for.
|
2008-11-12 15:43:33 +01:00
|
|
|
* \lfield size_hints A table with size hints of the client: user_position,
|
|
|
|
* user_size, program_position and program_size.
|
2008-07-01 19:37:10 +02:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_index(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
2008-08-11 11:09:44 +02:00
|
|
|
ssize_t slen;
|
2008-07-01 19:37:10 +02:00
|
|
|
client_t **c = luaA_checkudata(L, 1, "client");
|
|
|
|
const char *buf = luaL_checklstring(L, 2, &len);
|
2008-08-11 11:09:44 +02:00
|
|
|
char *value;
|
2008-07-08 18:34:32 +02:00
|
|
|
void *data;
|
2008-09-09 16:14:36 +02:00
|
|
|
xcb_get_wm_class_reply_t hint;
|
2008-07-08 18:34:32 +02:00
|
|
|
xcb_get_property_cookie_t prop_c;
|
|
|
|
xcb_get_property_reply_t *prop_r = NULL;
|
2008-08-15 02:00:58 +02:00
|
|
|
double d;
|
2008-07-01 19:37:10 +02:00
|
|
|
|
2008-07-31 17:29:05 +02:00
|
|
|
if((*c)->invalid)
|
|
|
|
luaL_error(L, "client is invalid\n");
|
|
|
|
|
2008-07-01 19:37:10 +02:00
|
|
|
if(luaA_usemetatable(L, 1, 2))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch(a_tokenize(buf, len))
|
|
|
|
{
|
|
|
|
case A_TK_NAME:
|
|
|
|
lua_pushstring(L, (*c)->name);
|
|
|
|
break;
|
2008-11-10 15:43:04 +01:00
|
|
|
case A_TK_TRANSIENT_FOR:
|
|
|
|
if((*c)->transient_for)
|
|
|
|
return luaA_client_userdata_new(L, (*c)->transient_for);
|
2008-12-07 11:06:58 +01:00
|
|
|
return 0;
|
2008-10-20 17:27:18 +02:00
|
|
|
case A_TK_SKIP_TASKBAR:
|
|
|
|
lua_pushboolean(L, (*c)->skiptb);
|
|
|
|
break;
|
2008-09-03 15:11:06 +02:00
|
|
|
case A_TK_TYPE:
|
|
|
|
switch((*c)->type)
|
|
|
|
{
|
|
|
|
case WINDOW_TYPE_DESKTOP:
|
|
|
|
lua_pushliteral(L, "desktop");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DOCK:
|
|
|
|
lua_pushliteral(L, "dock");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_SPLASH:
|
|
|
|
lua_pushliteral(L, "splash");
|
|
|
|
break;
|
|
|
|
case WINDOW_TYPE_DIALOG:
|
|
|
|
lua_pushliteral(L, "dialog");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lua_pushliteral(L, "normal");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-01 21:56:53 +02:00
|
|
|
case A_TK_CLASS:
|
2008-09-09 16:14:36 +02:00
|
|
|
if(!xcb_get_wm_class_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
|
|
|
|
&hint, NULL))
|
2008-07-26 08:45:35 +02:00
|
|
|
return 0;
|
2008-09-09 16:14:36 +02:00
|
|
|
lua_pushstring(L, hint.class);
|
|
|
|
xcb_get_wm_class_reply_wipe(&hint);
|
2008-07-26 08:45:35 +02:00
|
|
|
break;
|
|
|
|
case A_TK_INSTANCE:
|
2008-09-09 16:14:36 +02:00
|
|
|
if(!xcb_get_wm_class_reply(globalconf.connection,
|
|
|
|
xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
|
|
|
|
&hint, NULL))
|
2008-07-26 08:45:35 +02:00
|
|
|
return 0;
|
2008-09-09 16:14:36 +02:00
|
|
|
lua_pushstring(L, hint.name);
|
|
|
|
xcb_get_wm_class_reply_wipe(&hint);
|
2008-07-26 08:45:35 +02:00
|
|
|
break;
|
2008-08-28 11:29:21 +02:00
|
|
|
case A_TK_ROLE:
|
|
|
|
if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
|
|
|
|
WM_WINDOW_ROLE, &value, &slen))
|
|
|
|
return 0;
|
|
|
|
lua_pushlstring(L, value, slen);
|
|
|
|
p_delete(&value);
|
|
|
|
break;
|
2008-07-08 18:34:32 +02:00
|
|
|
case A_TK_PID:
|
|
|
|
prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
|
|
|
|
prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
|
|
|
|
|
|
|
|
if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
|
|
|
|
lua_pushnumber(L, *(uint32_t *)data);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p_delete(&prop_r);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2008-08-11 11:09:44 +02:00
|
|
|
case A_TK_MACHINE:
|
2008-08-11 13:27:28 +02:00
|
|
|
if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
|
|
|
|
WM_CLIENT_MACHINE, &value, &slen))
|
2008-08-11 11:09:44 +02:00
|
|
|
return 0;
|
|
|
|
lua_pushlstring(L, value, slen);
|
|
|
|
p_delete(&value);
|
|
|
|
break;
|
2008-08-11 11:41:42 +02:00
|
|
|
case A_TK_ICON_NAME:
|
2008-10-21 15:12:55 +02:00
|
|
|
lua_pushstring(L, (*c)->icon_name);
|
2008-08-11 11:41:42 +02:00
|
|
|
break;
|
2008-07-01 21:39:00 +02:00
|
|
|
case A_TK_SCREEN:
|
|
|
|
lua_pushnumber(L, 1 + (*c)->screen);
|
|
|
|
break;
|
2008-07-01 19:43:23 +02:00
|
|
|
case A_TK_HIDE:
|
|
|
|
lua_pushboolean(L, (*c)->ishidden);
|
|
|
|
break;
|
2008-09-06 13:52:05 +02:00
|
|
|
case A_TK_MINIMIZE:
|
|
|
|
lua_pushboolean(L, (*c)->isminimized);
|
|
|
|
break;
|
2008-08-21 17:58:08 +02:00
|
|
|
case A_TK_FULLSCREEN:
|
|
|
|
lua_pushboolean(L, (*c)->isfullscreen);
|
|
|
|
break;
|
2008-09-11 15:26:56 +02:00
|
|
|
case A_TK_ICON:
|
|
|
|
if((*c)->icon)
|
|
|
|
luaA_image_userdata_new(L, (*c)->icon);
|
|
|
|
else
|
|
|
|
return 0;
|
2008-07-01 19:49:35 +02:00
|
|
|
break;
|
2008-08-15 02:00:58 +02:00
|
|
|
case A_TK_OPACITY:
|
|
|
|
if((d = window_opacity_get((*c)->win)) >= 0)
|
|
|
|
lua_pushnumber(L, d);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
2008-07-01 19:55:18 +02:00
|
|
|
case A_TK_FLOATING:
|
2008-11-14 13:40:40 +01:00
|
|
|
lua_pushboolean(L, client_isfloating(*c));
|
2008-07-01 19:55:18 +02:00
|
|
|
break;
|
2008-08-21 17:52:44 +02:00
|
|
|
case A_TK_ONTOP:
|
|
|
|
lua_pushboolean(L, (*c)->isontop);
|
|
|
|
break;
|
2008-08-21 16:29:53 +02:00
|
|
|
case A_TK_STICKY:
|
|
|
|
lua_pushboolean(L, (*c)->issticky);
|
|
|
|
break;
|
2008-07-01 19:59:36 +02:00
|
|
|
case A_TK_HONORSIZEHINTS:
|
|
|
|
lua_pushboolean(L, (*c)->honorsizehints);
|
2008-07-01 19:37:10 +02:00
|
|
|
break;
|
2008-07-01 20:07:21 +02:00
|
|
|
case A_TK_BORDER_WIDTH:
|
|
|
|
lua_pushnumber(L, (*c)->border);
|
|
|
|
break;
|
|
|
|
case A_TK_BORDER_COLOR:
|
2008-07-02 11:04:17 +02:00
|
|
|
luaA_pushcolor(L, &(*c)->border_color);
|
2008-07-01 22:08:27 +02:00
|
|
|
break;
|
2008-07-01 22:19:23 +02:00
|
|
|
case A_TK_TITLEBAR:
|
|
|
|
if((*c)->titlebar)
|
2008-09-21 20:39:23 +02:00
|
|
|
return luaA_wibox_userdata_new(L, (*c)->titlebar);
|
2008-07-01 22:19:23 +02:00
|
|
|
return 0;
|
2008-07-29 14:37:17 +02:00
|
|
|
case A_TK_URGENT:
|
|
|
|
lua_pushboolean(L, (*c)->isurgent);
|
|
|
|
break;
|
2008-11-12 15:43:33 +01:00
|
|
|
case A_TK_SIZE_HINTS:
|
2008-09-30 11:45:41 +02:00
|
|
|
lua_newtable(L);
|
|
|
|
lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
|
|
|
|
lua_setfield(L, -2, "user_position");
|
|
|
|
lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
|
|
|
|
lua_setfield(L, -2, "user_size");
|
|
|
|
lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
|
|
|
|
lua_setfield(L, -2, "program_position");
|
|
|
|
lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
|
|
|
|
lua_setfield(L, -2, "program_size");
|
|
|
|
break;
|
2008-07-01 19:59:36 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
2008-07-01 19:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-08-12 13:23:10 +02:00
|
|
|
/** Get or set mouse buttons bindings for a client.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of element pushed on stack.
|
|
|
|
* \luastack
|
|
|
|
* \lvalue A client.
|
|
|
|
* \lparam An array of mouse button bindings objects, or nothing.
|
|
|
|
* \return The array of mouse button bindings objects of this client.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_buttons(lua_State *L)
|
|
|
|
{
|
|
|
|
client_t **client = luaA_checkudata(L, 1, "client");
|
|
|
|
button_array_t *buttons = &(*client)->buttons;
|
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
luaA_button_array_set(L, 2, buttons);
|
|
|
|
|
|
|
|
return luaA_button_array_get(L, buttons);
|
|
|
|
}
|
|
|
|
|
2008-08-12 12:08:20 +02:00
|
|
|
/* Client module.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of pushed elements.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_module_index(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *buf = luaL_checklstring(L, 2, &len);
|
|
|
|
|
|
|
|
switch(a_tokenize(buf, len))
|
|
|
|
{
|
|
|
|
case A_TK_FOCUS:
|
|
|
|
if(globalconf.screen_focus->client_focus)
|
|
|
|
luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Client module new index.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of pushed elements.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_module_newindex(lua_State *L)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
const char *buf = luaL_checklstring(L, 2, &len);
|
|
|
|
client_t **c;
|
|
|
|
|
|
|
|
switch(a_tokenize(buf, len))
|
|
|
|
{
|
|
|
|
case A_TK_FOCUS:
|
|
|
|
c = luaA_checkudata(L, 3, "client");
|
|
|
|
client_focus(*c);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-14 16:16:09 +01:00
|
|
|
/** Move a client with mouse (DEPRECATED).
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_mouse_move(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_deprecate(L, "awful.mouse.client.move()");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-17 17:12:54 +01:00
|
|
|
/** Resize a client with mouse (DEPRECATED).
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \return The number of pushed elements.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
luaA_client_mouse_resize(lua_State *L)
|
|
|
|
{
|
|
|
|
luaA_deprecate(L, "awful.mouse.client.resize()");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
const struct luaL_reg awesome_client_methods[] =
|
|
|
|
{
|
|
|
|
{ "get", luaA_client_get },
|
2008-08-12 12:08:20 +02:00
|
|
|
{ "__index", luaA_client_module_index },
|
|
|
|
{ "__newindex", luaA_client_module_newindex },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
const struct luaL_reg awesome_client_meta[] =
|
|
|
|
{
|
2008-09-18 15:07:34 +02:00
|
|
|
{ "isvisible", luaA_client_isvisible },
|
2008-10-21 15:31:52 +02:00
|
|
|
{ "geometry", luaA_client_geometry },
|
|
|
|
{ "fullgeometry", luaA_client_fullgeometry },
|
2008-08-12 13:23:10 +02:00
|
|
|
{ "buttons", luaA_client_buttons },
|
2008-08-13 17:49:57 +02:00
|
|
|
{ "tags", luaA_client_tags },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "kill", luaA_client_kill },
|
|
|
|
{ "swap", luaA_client_swap },
|
2008-05-26 16:17:57 +02:00
|
|
|
{ "raise", luaA_client_raise },
|
2008-11-12 11:27:58 +01:00
|
|
|
{ "lower", luaA_client_lower },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "redraw", luaA_client_redraw },
|
2008-05-26 16:17:57 +02:00
|
|
|
{ "mouse_resize", luaA_client_mouse_resize },
|
|
|
|
{ "mouse_move", luaA_client_mouse_move },
|
2008-06-02 08:31:54 +02:00
|
|
|
{ "unmanage", luaA_client_unmanage },
|
2008-07-01 19:37:10 +02:00
|
|
|
{ "__index", luaA_client_index },
|
|
|
|
{ "__newindex", luaA_client_newindex },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "__eq", luaA_client_eq },
|
2008-07-31 17:29:05 +02:00
|
|
|
{ "__gc", luaA_client_gc },
|
2008-05-20 15:39:47 +02:00
|
|
|
{ "__tostring", luaA_client_tostring },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|