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
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_aux.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
|
|
|
#include <xcb/shape.h>
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-01-01 17:25:48 +01:00
|
|
|
#include "client.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "tag.h"
|
2007-11-13 21:40:33 +01:00
|
|
|
#include "rules.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
#include "window.h"
|
2007-12-14 21:51:54 +01:00
|
|
|
#include "focus.h"
|
2007-12-27 18:01:36 +01:00
|
|
|
#include "ewmh.h"
|
2008-01-07 18:12:38 +01:00
|
|
|
#include "widget.h"
|
2008-03-13 09:05:34 +01:00
|
|
|
#include "screen.h"
|
2008-03-15 13:59:04 +01:00
|
|
|
#include "titlebar.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-03-13 09:05:34 +01:00
|
|
|
#include "common/xutil.h"
|
|
|
|
#include "common/xscreen.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2007-12-14 14:29:32 +01:00
|
|
|
/** Load windows properties, restoring client's tag
|
|
|
|
* and floating state before awesome was restarted if any
|
|
|
|
* \todo this may bug if number of tags is != than before
|
2008-04-11 11:35:11 +02:00
|
|
|
* \param c client ref
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param screen Screen ID
|
2008-01-17 14:19:13 +01:00
|
|
|
* \return true if client had property
|
2007-10-17 11:49:54 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
static bool
|
2008-04-11 11:35:11 +02:00
|
|
|
client_loadprops(client_t * c, int screen)
|
2007-10-16 22:40:02 +02:00
|
|
|
{
|
2007-12-14 19:02:38 +01:00
|
|
|
int i, ntags = 0;
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
2007-12-14 14:29:32 +01:00
|
|
|
char *prop;
|
2008-03-21 16:50:17 +01:00
|
|
|
bool result = false;
|
2007-10-16 22:40:02 +02:00
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
2007-12-14 19:02:38 +01:00
|
|
|
ntags++;
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2008-04-08 19:52:59 +02:00
|
|
|
prop = p_new(char, ntags + 3);
|
2007-12-14 19:02:38 +01:00
|
|
|
|
2008-04-09 13:46:42 +02:00
|
|
|
if(xutil_gettextprop(globalconf.connection, c->win,
|
|
|
|
xutil_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"),
|
|
|
|
prop, ntags + 3))
|
2007-12-14 14:29:32 +01:00
|
|
|
{
|
2007-12-16 02:45:38 +01:00
|
|
|
for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
|
2007-12-14 14:29:32 +01:00
|
|
|
if(prop[i] == '1')
|
|
|
|
{
|
2007-12-27 22:43:59 +01:00
|
|
|
tag_client(c, tag);
|
2008-03-21 16:50:17 +01:00
|
|
|
result = true;
|
2007-12-14 14:29:32 +01:00
|
|
|
}
|
|
|
|
else
|
2007-12-27 22:43:59 +01:00
|
|
|
untag_client(c, tag);
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2008-04-08 19:52:59 +02:00
|
|
|
if(prop[i])
|
2008-04-09 13:53:18 +02:00
|
|
|
client_setfloating(c, prop[i] == '1', (prop[i + 1] >= 0 && prop[i + 1] <= LAYER_FULLSCREEN) ? atoi(&prop[i + 1]) : prop[i] == '1' ? LAYER_FLOAT : LAYER_TILE);
|
2007-12-14 14:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
p_delete(&prop);
|
|
|
|
|
|
|
|
return result;
|
2007-10-16 22:40:02 +02:00
|
|
|
}
|
|
|
|
|
2007-09-11 13:14:43 +02:00
|
|
|
/** Check if client supports protocol WM_DELETE_WINDOW
|
2007-12-16 03:14:47 +01:00
|
|
|
* \param disp the display
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param win the Window
|
2008-03-21 16:50:17 +01:00
|
|
|
* \return true if client has WM_DELETE_WINDOW
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
static bool
|
|
|
|
client_isprotodel(xcb_connection_t *c, xcb_window_t win)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
uint32_t i, n;
|
|
|
|
xcb_atom_t *protocols;
|
|
|
|
bool ret = false;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(xcb_get_wm_protocols(c, win, &n, &protocols))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
for(i = 0; !ret && i < n; i++)
|
2008-03-26 19:58:30 +01:00
|
|
|
if(protocols[i] == xutil_intern_atom(c, "WM_DELETE_WINDOW"))
|
2008-03-21 16:50:17 +01:00
|
|
|
ret = true;
|
|
|
|
p_delete(&protocols);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-09 17:33:47 +02:00
|
|
|
/** Returns true if a client is tagged
|
|
|
|
* with one of the tags in any screen.
|
|
|
|
* \return true or false
|
|
|
|
*/
|
|
|
|
static bool
|
2008-04-11 11:35:11 +02:00
|
|
|
client_isvisible_anyscreen(client_t *c)
|
2008-04-09 17:33:47 +02:00
|
|
|
{
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
2008-04-09 17:33:47 +02:00
|
|
|
int screen;
|
|
|
|
|
|
|
|
if(!c)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(globalconf.scratch.client == c)
|
|
|
|
return globalconf.scratch.isvisible;
|
|
|
|
|
|
|
|
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
|
|
|
|
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
|
|
|
if(tag->selected && is_client_tagged(c, tag))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns true if a client is tagged
|
|
|
|
* with one of the tags.
|
|
|
|
* \param c the client
|
|
|
|
* \param screen number
|
|
|
|
* \return true or false
|
|
|
|
*/
|
|
|
|
bool
|
2008-04-11 11:35:11 +02:00
|
|
|
client_isvisible(client_t *c, int screen)
|
2008-04-09 17:33:47 +02:00
|
|
|
{
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
2008-04-09 17:33:47 +02:00
|
|
|
|
|
|
|
if(!c || c->screen != screen)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(globalconf.scratch.client == c)
|
|
|
|
return globalconf.scratch.isvisible;
|
|
|
|
|
|
|
|
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
|
|
|
if(tag->selected && is_client_tagged(c, tag))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2008-04-11 11:35:11 +02:00
|
|
|
/** Get a client by its window
|
|
|
|
* \param list client_t list to look info
|
|
|
|
* \param w client_t window to find
|
2007-12-14 14:29:32 +01:00
|
|
|
* \return client
|
|
|
|
*/
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *
|
|
|
|
client_get_bywin(client_t *list, xcb_window_t w)
|
2007-12-14 14:29:32 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2007-12-14 14:29:32 +01:00
|
|
|
|
|
|
|
for(c = list; c && c->win != w; c = c->next);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
/** Get a client by its name
|
2008-04-11 11:35:11 +02:00
|
|
|
* \param list client_t list
|
2007-12-30 15:08:38 +01:00
|
|
|
* \param name name to search
|
|
|
|
* \return first matching client
|
|
|
|
*/
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *
|
|
|
|
client_get_byname(client_t *list, char *name)
|
2007-12-23 16:16:02 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2007-12-23 16:16:02 +01:00
|
|
|
|
|
|
|
for(c = list; c; c = c->next)
|
|
|
|
if(strstr(c->name, name))
|
|
|
|
return c;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
/** Update client name attribute with its title
|
|
|
|
* \param c the client
|
|
|
|
*/
|
2007-10-01 20:44:02 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_updatetitle(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-04-23 13:22:58 +02:00
|
|
|
char buf[512];
|
|
|
|
|
2008-04-09 13:46:42 +02:00
|
|
|
if(!xutil_gettextprop(globalconf.connection, c->win,
|
|
|
|
xutil_intern_atom(globalconf.connection, "_NET_WM_NAME"),
|
2008-04-28 13:02:26 +02:00
|
|
|
buf, ssizeof(buf)))
|
2008-04-09 13:46:42 +02:00
|
|
|
xutil_gettextprop(globalconf.connection, c->win,
|
|
|
|
xutil_intern_atom(globalconf.connection, "WM_NAME"),
|
2008-04-28 13:02:26 +02:00
|
|
|
buf, ssizeof(buf));
|
2008-04-23 13:22:58 +02:00
|
|
|
if(c->name)
|
|
|
|
p_delete(&c->name);
|
2008-04-28 17:46:52 +02:00
|
|
|
c->name = a_strndup(buf, ssizeof(buf));
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
2008-01-07 18:54:45 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
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-02-04 14:54:50 +01:00
|
|
|
if(globalconf.screens[c->screen].opacity_unfocused != -1)
|
|
|
|
window_settrans(c->win, globalconf.screens[c->screen].opacity_unfocused);
|
2008-04-10 13:18:08 +02:00
|
|
|
else if(globalconf.screens[c->screen].opacity_focused != -1)
|
|
|
|
window_settrans(c->win, -1);
|
2008-03-14 14:27:56 +01:00
|
|
|
focus_add_client(NULL);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL,
|
|
|
|
&globalconf.screens[c->screen].styles.normal.border.pixel);
|
2008-01-25 12:55:44 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
2008-01-25 12:55:44 +01:00
|
|
|
}
|
|
|
|
|
2007-12-14 08:47:21 +01:00
|
|
|
/** Ban client and unmap it
|
2007-09-05 20:15:00 +02:00
|
|
|
* \param c the client
|
|
|
|
*/
|
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_ban(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-25 12:55:44 +01:00
|
|
|
if(globalconf.focus->client == c)
|
|
|
|
client_unfocus(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_unmap_window(globalconf.connection, c->win);
|
|
|
|
window_setstate(c->win, XCB_WM_ICONIC_STATE);
|
2008-03-27 17:01:57 +01:00
|
|
|
if(c->titlebar.position && c->titlebar.sw)
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_unmap_window(globalconf.connection, c->titlebar.sw->window);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Give focus to client, or to first client if c is NULL
|
|
|
|
* \param c client
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param screen Screen ID
|
2008-03-25 11:28:07 +01:00
|
|
|
* \param raise raise window if true
|
|
|
|
* \return true if a window (even root) has received focus, false otherwise
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
bool
|
2008-04-11 11:35:11 +02:00
|
|
|
client_focus(client_t *c, int screen, bool raise)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-25 18:20:39 +01:00
|
|
|
int phys_screen;
|
|
|
|
|
2007-12-28 10:12:34 +01:00
|
|
|
/* if c is NULL or invisible, take next client in the focus history */
|
2008-03-25 11:28:07 +01:00
|
|
|
if((!c || (c && (!client_isvisible(c, screen))))
|
|
|
|
&& !(c = focus_get_current_client(screen)))
|
2007-12-28 10:12:34 +01:00
|
|
|
/* if c is still NULL take next client in the stack */
|
2008-03-25 11:28:07 +01:00
|
|
|
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
|
2007-10-03 17:26:14 +02:00
|
|
|
|
2008-03-25 11:28:07 +01:00
|
|
|
/* if c is already the focused window, then stop */
|
2008-03-16 20:29:30 +01:00
|
|
|
if(c == globalconf.focus->client)
|
2008-03-21 16:50:17 +01:00
|
|
|
return false;
|
2008-03-16 20:29:30 +01:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
/* unfocus current selected client */
|
|
|
|
if(globalconf.focus->client)
|
|
|
|
client_unfocus(globalconf.focus->client);
|
2007-12-14 21:51:54 +01:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
if(c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-02-08 15:08:42 +01:00
|
|
|
/* unban the client before focusing or it will fail */
|
|
|
|
client_unban(c);
|
2008-01-25 23:43:16 +01:00
|
|
|
/* save sel in focus history */
|
2008-01-25 22:50:18 +01:00
|
|
|
focus_add_client(c);
|
2008-04-08 16:27:27 +02:00
|
|
|
if(globalconf.screens[c->screen].opacity_focused != -1)
|
2008-03-23 20:36:55 +01:00
|
|
|
window_settrans(c->win, globalconf.screens[c->screen].opacity_focused);
|
2008-04-10 13:18:08 +02:00
|
|
|
else if(globalconf.screens[c->screen].opacity_unfocused != -1)
|
|
|
|
window_settrans(c->win, -1);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_window_attributes(globalconf.connection, c->win, XCB_CW_BORDER_PIXEL,
|
|
|
|
&globalconf.screens[screen].styles.focus.border.pixel);
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
|
|
|
|
c->win, XCB_CURRENT_TIME);
|
2008-02-09 23:12:40 +01:00
|
|
|
if(raise)
|
2008-03-24 16:34:41 +01:00
|
|
|
client_stack(c);
|
2008-01-26 13:11:12 +01:00
|
|
|
/* since we're dropping EnterWindow events and sometimes the window
|
|
|
|
* will appear under the mouse, grabbuttons */
|
2008-03-21 11:33:50 +01:00
|
|
|
window_grabbuttons(c->win, c->phys_screen);
|
2008-03-25 18:20:39 +01:00
|
|
|
phys_screen = c->phys_screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
2008-03-25 18:20:39 +01:00
|
|
|
{
|
|
|
|
phys_screen = screen_virttophys(screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_set_input_focus(globalconf.connection,
|
|
|
|
XCB_INPUT_FOCUS_POINTER_ROOT,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
XCB_CURRENT_TIME);
|
2008-03-25 18:20:39 +01:00
|
|
|
}
|
2007-12-28 13:43:47 +01:00
|
|
|
|
2008-03-25 18:20:39 +01:00
|
|
|
ewmh_update_net_active_window(phys_screen);
|
2008-01-25 12:55:44 +01:00
|
|
|
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
|
2008-03-25 11:28:07 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
return true;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-24 16:34:41 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_stack(client_t *c)
|
2008-03-24 16:34:41 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
uint32_t config_win_vals[2];
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *client;
|
2008-04-10 11:52:03 +02:00
|
|
|
layer_t layer;
|
2008-03-24 16:34:41 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
config_win_vals[0] = XCB_NONE;
|
|
|
|
config_win_vals[1] = XCB_STACK_MODE_ABOVE;
|
2008-04-08 19:52:59 +02:00
|
|
|
|
2008-04-09 17:33:47 +02:00
|
|
|
for(layer = LAYER_DESKTOP; layer < LAYER_FULLSCREEN; layer++)
|
2008-03-24 16:34:41 +01:00
|
|
|
{
|
2008-04-09 17:33:47 +02:00
|
|
|
/* \todo we need to maintain a separate stack list */
|
2008-03-24 16:34:41 +01:00
|
|
|
for(client = globalconf.clients; client; client = client->next)
|
2008-04-08 19:52:59 +02:00
|
|
|
{
|
2008-04-09 17:33:47 +02:00
|
|
|
if(client->layer == layer && client != c
|
|
|
|
&& client_isvisible_anyscreen(client))
|
2008-03-24 16:34:41 +01:00
|
|
|
{
|
|
|
|
if(client->titlebar.position && client->titlebar.sw)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection,
|
|
|
|
client->titlebar.sw->window,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] = client->titlebar.sw->window;
|
2008-03-24 16:34:41 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection, client->win,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] = client->win;
|
2008-03-24 16:34:41 +01:00
|
|
|
}
|
|
|
|
}
|
2008-04-08 19:52:59 +02:00
|
|
|
if(c->layer == layer)
|
|
|
|
{
|
|
|
|
if(c->titlebar.position && c->titlebar.sw)
|
2008-03-24 16:34:41 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection, c->titlebar.sw->window,
|
|
|
|
XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
|
|
|
|
config_win_vals);
|
|
|
|
config_win_vals[0] = c->titlebar.sw->window;
|
2008-03-24 16:34:41 +01:00
|
|
|
}
|
2008-03-21 16:50:17 +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-04-08 19:52:59 +02:00
|
|
|
}
|
2008-03-24 16:34:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:27:43 +02:00
|
|
|
/** Manage a new client
|
|
|
|
* \param w The window
|
2008-03-22 14:59:03 +01:00
|
|
|
* \param wgeom Window geometry
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param screen Screen ID
|
2007-09-20 21:27:43 +02:00
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-03-22 14:59:03 +01:00
|
|
|
client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c, *t = NULL;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_window_t trans;
|
|
|
|
bool rettrans, retloadprops;
|
|
|
|
uint32_t config_win_val;
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
2008-04-10 11:55:36 +02:00
|
|
|
rule_t *rule;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_t *u_size_hints;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-04-11 11:35:11 +02:00
|
|
|
c = p_new(client_t, 1);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-03-22 14:59:03 +01:00
|
|
|
c->screen = screen_get_bycoord(globalconf.screens_info, screen, wgeom->x, wgeom->y);
|
2008-01-22 09:50:24 +01:00
|
|
|
|
2008-03-21 10:53:17 +01:00
|
|
|
if(globalconf.screens_info->xinerama_is_active)
|
2008-03-21 16:50:17 +01:00
|
|
|
c->phys_screen = globalconf.default_screen;
|
2008-03-21 10:53:17 +01:00
|
|
|
else
|
|
|
|
c->phys_screen = c->screen;
|
|
|
|
|
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;
|
|
|
|
c->oldborder = wgeom->border_width;
|
2008-03-21 16:50:17 +01:00
|
|
|
c->newcomer = true;
|
2008-04-08 19:52:59 +02:00
|
|
|
c->layer = c->oldlayer = LAYER_TILE;
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* Set windows borders */
|
2008-03-21 16:50:17 +01:00
|
|
|
config_win_val = c->border = globalconf.screens[screen].borderpx;
|
|
|
|
xcb_configure_window(globalconf.connection, w, XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
|
|
|
&config_win_val);
|
2008-03-22 14:27:54 +01:00
|
|
|
xcb_change_window_attributes(globalconf.connection, w, XCB_CW_BORDER_PIXEL,
|
|
|
|
&config_win_val);
|
2008-01-13 16:30:43 +01:00
|
|
|
/* propagates border_width, if size doesn't change */
|
|
|
|
window_configure(c->win, c->geometry, c->border);
|
2007-11-13 22:41:56 +01:00
|
|
|
|
|
|
|
/* update window title */
|
2007-12-14 16:05:10 +01:00
|
|
|
client_updatetitle(c);
|
2007-11-13 22:41:56 +01:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* update hints */
|
2008-03-21 16:50:17 +01:00
|
|
|
u_size_hints = client_updatesizehints(c);
|
2008-01-13 16:30:43 +01:00
|
|
|
client_updatewmhints(c);
|
2007-12-28 20:48:29 +01:00
|
|
|
|
2008-03-15 14:46:45 +01:00
|
|
|
/* Try to load props if any */
|
2008-03-23 21:54:55 +01:00
|
|
|
if(!(retloadprops = client_loadprops(c, screen)))
|
2008-03-21 16:50:17 +01:00
|
|
|
move_client_to_screen(c, screen, true);
|
2008-03-15 14:46:45 +01:00
|
|
|
|
|
|
|
/* Then check clients hints */
|
2007-12-28 20:48:29 +01:00
|
|
|
ewmh_check_client_hints(c);
|
2008-01-13 16:30:43 +01:00
|
|
|
|
2008-03-14 17:33:10 +01:00
|
|
|
/* default titlebar position */
|
2008-03-15 11:13:45 +01:00
|
|
|
c->titlebar = globalconf.screens[screen].titlebar_default;
|
2008-03-14 17:33:10 +01:00
|
|
|
|
2008-03-14 17:34:25 +01:00
|
|
|
/* get the matching rule if any */
|
|
|
|
rule = rule_matching_client(c);
|
|
|
|
|
2008-03-15 14:46:45 +01:00
|
|
|
/* Then apply rules if no props */
|
2008-03-23 21:54:55 +01:00
|
|
|
if(!retloadprops && rule)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-23 21:54:55 +01:00
|
|
|
if(rule->screen != RULE_NOSCREEN)
|
2008-03-21 16:50:17 +01:00
|
|
|
move_client_to_screen(c, rule->screen, true);
|
2008-03-23 21:54:55 +01:00
|
|
|
tag_client_with_rule(c, rule);
|
2008-01-13 18:32:25 +01:00
|
|
|
|
2008-03-23 21:54:55 +01:00
|
|
|
switch(rule->isfloating)
|
|
|
|
{
|
|
|
|
case Maybe:
|
|
|
|
break;
|
|
|
|
case Yes:
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
2008-03-23 21:54:55 +01:00
|
|
|
break;
|
|
|
|
case No:
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, false, LAYER_TILE);
|
2008-03-23 21:54:55 +01:00
|
|
|
break;
|
2008-01-13 16:30:43 +01:00
|
|
|
}
|
2008-03-23 21:54:55 +01:00
|
|
|
|
|
|
|
if(rule->opacity >= 0.0f)
|
|
|
|
window_settrans(c->win, rule->opacity);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
/* check for transient and set tags like its parent */
|
2008-03-26 19:58:30 +01:00
|
|
|
if((rettrans = xutil_get_transient_for_hint(globalconf.connection, w, &trans))
|
2008-02-12 10:19:59 +01:00
|
|
|
&& (t = client_get_bywin(globalconf.clients, trans)))
|
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
|
|
|
if(is_client_tagged(t, tag))
|
|
|
|
tag_client(c, tag);
|
|
|
|
|
|
|
|
/* should be floating if transsient or fixed */
|
2008-03-28 11:35:56 +01:00
|
|
|
if(rettrans || c->isfixed)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, c->layer != LAYER_TILE ? c->layer : LAYER_FLOAT);
|
2008-02-12 10:19:59 +01:00
|
|
|
|
2008-03-17 08:56:17 +01:00
|
|
|
/* titlebar init */
|
|
|
|
if(rule && rule->titlebar.position != Auto)
|
|
|
|
c->titlebar = rule->titlebar;
|
|
|
|
|
|
|
|
titlebar_init(c);
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(!retloadprops
|
|
|
|
&& u_size_hints
|
2008-04-27 13:26:39 +02:00
|
|
|
&& !(xcb_size_hints_get_flags(u_size_hints) & (XCB_SIZE_US_POSITION_HINT |
|
|
|
|
XCB_SIZE_P_POSITION_HINT)))
|
2008-04-03 09:04:18 +02:00
|
|
|
{
|
2008-04-08 15:40:33 +02:00
|
|
|
if(c->isfloating && !c->ismax)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(c, globalconf.screens[c->screen].floating_placement(c), false);
|
2008-04-03 20:11:38 +02:00
|
|
|
else
|
|
|
|
c->f_geometry = globalconf.screens[c->screen].floating_placement(c);
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
xcb_free_size_hints(u_size_hints);
|
2008-04-03 09:04:18 +02:00
|
|
|
}
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-03-18 11:09:18 +01:00
|
|
|
/* update titlebar with real floating info now */
|
2008-04-04 10:53:53 +02:00
|
|
|
titlebar_update_geometry_floating(c);
|
2008-03-18 11:09:18 +01:00
|
|
|
|
2008-03-22 18:47:13 +01:00
|
|
|
const uint32_t select_input_val[] = {
|
|
|
|
XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE |
|
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW };
|
|
|
|
|
|
|
|
xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK,
|
|
|
|
select_input_val);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
|
|
|
/* handle xshape */
|
2007-12-16 02:45:38 +01:00
|
|
|
if(globalconf.have_shape)
|
2007-09-13 15:57:35 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_shape_select_input(globalconf.connection, w, true);
|
2008-03-21 11:33:50 +01:00
|
|
|
window_setshape(c->win, c->phys_screen);
|
2007-09-13 15:57:35 +02:00
|
|
|
}
|
2007-10-22 16:25:27 +02:00
|
|
|
|
|
|
|
/* attach to the stack */
|
2008-03-14 17:34:25 +01:00
|
|
|
if(rule)
|
2008-02-05 17:31:37 +01:00
|
|
|
switch(rule->ismaster)
|
|
|
|
{
|
|
|
|
case Yes:
|
|
|
|
client_list_push(&globalconf.clients, c);
|
|
|
|
break;
|
|
|
|
case No:
|
|
|
|
client_list_append(&globalconf.clients, c);
|
|
|
|
break;
|
2008-03-14 17:33:10 +01:00
|
|
|
case Maybe:
|
2008-02-05 17:31:37 +01:00
|
|
|
rule = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!rule)
|
|
|
|
{
|
|
|
|
if(globalconf.screens[c->screen].new_become_master)
|
|
|
|
client_list_push(&globalconf.clients, c);
|
|
|
|
else
|
|
|
|
client_list_append(&globalconf.clients, c);
|
|
|
|
}
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-01-11 16:44:24 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-03-21 10:53:17 +01:00
|
|
|
ewmh_update_net_client_list(c->phys_screen);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-03-16 10:01:55 +01:00
|
|
|
static 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;
|
|
|
|
}
|
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
/** Resize client window
|
|
|
|
* \param c client to resize
|
2008-01-11 13:37:33 +01:00
|
|
|
* \param geometry new window geometry
|
2008-03-16 10:01:55 +01:00
|
|
|
* \param hints use resize hints
|
2008-03-21 16:50:17 +01:00
|
|
|
* \param return true if resize has been done
|
2007-12-30 15:08:38 +01:00
|
|
|
*/
|
2008-03-21 16:50:17 +01:00
|
|
|
bool
|
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-01-06 14:40:23 +01:00
|
|
|
int new_screen;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area;
|
2008-03-16 10:01:55 +01:00
|
|
|
Layout *layout = layout_get_current(c->screen);
|
2008-03-21 16:50:17 +01:00
|
|
|
bool resized = false;
|
2008-03-16 10:01:55 +01:00
|
|
|
|
2008-03-26 10:57:06 +01:00
|
|
|
if(!c->ismoving && !c->isfloating && layout->arrange != layout_floating)
|
|
|
|
{
|
|
|
|
titlebar_update_geometry(c, geometry);
|
|
|
|
geometry = titlebar_geometry_remove(&c->titlebar, geometry);
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
/* Values to configure a window is an array where values are
|
|
|
|
* stored according to 'value_mask' */
|
|
|
|
uint32_t values[5];
|
|
|
|
|
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-03-21 16:50:17 +01:00
|
|
|
return false;
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
/* offscreen appearance fixes */
|
2008-03-21 10:53:17 +01:00
|
|
|
area = get_display_area(c->phys_screen, NULL,
|
2007-12-23 00:54:59 +01:00
|
|
|
&globalconf.screens[c->screen].padding);
|
2008-03-16 11:06:08 +01:00
|
|
|
|
2008-01-05 20:18:30 +01:00
|
|
|
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-01-06 14:40:23 +01:00
|
|
|
|
2008-01-05 20:18:30 +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-03-16 10:01:55 +01:00
|
|
|
new_screen =
|
|
|
|
screen_get_bycoord(globalconf.screens_info, c->screen, geometry.x, geometry.y);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
c->geometry.x = values[0] = geometry.x;
|
|
|
|
c->geometry.width = values[2] = geometry.width;
|
|
|
|
c->geometry.y = values[1] = geometry.y;
|
|
|
|
c->geometry.height = values[3] = geometry.height;
|
|
|
|
values[4] = c->border;
|
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-03-16 17:51:46 +01:00
|
|
|
if(c->ismoving || c->isfloating
|
2008-03-14 16:16:42 +01:00
|
|
|
|| layout_get_current(new_screen)->arrange == layout_floating)
|
|
|
|
{
|
|
|
|
if(!c->ismax)
|
|
|
|
c->f_geometry = geometry;
|
2008-03-16 17:28:04 +01:00
|
|
|
titlebar_update_geometry_floating(c);
|
2008-03-14 16:16:42 +01:00
|
|
|
}
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_configure_window(globalconf.connection, c->win,
|
|
|
|
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
|
|
|
|
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
|
|
|
|
XCB_CONFIG_WINDOW_BORDER_WIDTH,
|
|
|
|
values);
|
2008-01-06 14:40:23 +01:00
|
|
|
window_configure(c->win, geometry, c->border);
|
|
|
|
|
|
|
|
if(c->screen != new_screen)
|
2008-03-21 16:50:17 +01:00
|
|
|
move_client_to_screen(c, new_screen, false);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
resized = true;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-03-26 11:03:52 +01:00
|
|
|
|
|
|
|
/* call it again like it was floating,
|
|
|
|
* we want it to be sticked to the window */
|
2008-03-26 11:07:23 +01:00
|
|
|
if(!c->ismoving && !c->isfloating && layout->arrange != layout_floating)
|
2008-03-26 11:03:52 +01:00
|
|
|
titlebar_update_geometry_floating(c);
|
|
|
|
|
|
|
|
return resized;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-01-17 10:40:39 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_setfloating(client_t *c, bool floating, layer_t layer)
|
2008-01-17 10:40:39 +01:00
|
|
|
{
|
|
|
|
if(c->isfloating != floating)
|
2008-01-17 19:17:53 +01:00
|
|
|
{
|
2008-01-17 10:40:39 +01:00
|
|
|
if((c->isfloating = floating))
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(c, c->f_geometry, false);
|
2008-04-02 14:48:42 +02:00
|
|
|
else if(c->ismax)
|
2008-01-24 20:07:17 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
c->ismax = false;
|
|
|
|
client_resize(c, c->m_geometry, false);
|
2008-01-24 20:07:17 +01:00
|
|
|
}
|
2008-01-18 09:34:52 +01:00
|
|
|
if(client_isvisible(c, c->screen))
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
2008-01-17 19:17:53 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-04-08 19:52:59 +02:00
|
|
|
if(floating)
|
|
|
|
{
|
|
|
|
c->oldlayer = c->layer;
|
|
|
|
c->layer = layer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c->layer = c->oldlayer;
|
|
|
|
}
|
|
|
|
client_stack(c);
|
2008-01-24 20:07:17 +01:00
|
|
|
client_saveprops(c);
|
2008-01-17 19:17:53 +01:00
|
|
|
}
|
2008-01-17 10:40:39 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
/** Save client properties as an X property
|
|
|
|
* \param c client
|
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_saveprops(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-12-14 19:02:38 +01:00
|
|
|
int i = 0, ntags = 0;
|
2007-09-07 11:18:27 +02:00
|
|
|
char *prop;
|
2008-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
2007-12-14 19:02:38 +01:00
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
2007-12-14 19:02:38 +01:00
|
|
|
ntags++;
|
2007-09-07 11:18:27 +02:00
|
|
|
|
2008-04-08 19:52:59 +02:00
|
|
|
prop = p_new(char, ntags + 3);
|
2007-09-06 22:02:50 +02:00
|
|
|
|
2007-12-30 15:08:38 +01:00
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
|
2007-12-27 23:05:34 +01:00
|
|
|
prop[i] = is_client_tagged(c, tag) ? '1' : '0';
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-04-08 19:52:59 +02:00
|
|
|
prop[i] = c->isfloating ? '1' : '0';
|
|
|
|
|
|
|
|
sprintf(&prop[++i], "%d", c->layer);
|
2007-09-07 11:18:27 +02:00
|
|
|
|
|
|
|
prop[++i] = '\0';
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win,
|
2008-03-26 19:58:30 +01:00
|
|
|
xutil_intern_atom(globalconf.connection, "_AWESOME_PROPERTIES"),
|
2008-03-21 16:50:17 +01:00
|
|
|
STRING, 8, i, (unsigned char *) prop);
|
2007-09-07 11:18:27 +02:00
|
|
|
|
|
|
|
p_delete(&prop);
|
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-03-21 16:50:17 +01:00
|
|
|
xcb_map_window(globalconf.connection, c->win);
|
|
|
|
window_setstate(c->win, XCB_WM_NORMAL_STATE);
|
2008-03-14 18:20:00 +01:00
|
|
|
if(c->titlebar.sw && c->titlebar.position != Off)
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_map_window(globalconf.connection, c->titlebar.sw->window);
|
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-04-22 14:18:09 +02:00
|
|
|
tag_t *tag;
|
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
|
|
|
|
|
|
|
/* remove client everywhere */
|
2008-01-12 17:01:21 +01:00
|
|
|
client_list_detach(&globalconf.clients, c);
|
2007-12-17 03:56:29 +01:00
|
|
|
focus_delete_client(c);
|
2008-02-26 17:45:55 +01:00
|
|
|
if(globalconf.scratch.client == c)
|
|
|
|
globalconf.scratch.client = NULL;
|
2007-12-16 02:45:38 +01:00
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
2007-12-27 22:43:59 +01:00
|
|
|
untag_client(c, tag);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
|
|
|
if(globalconf.focus->client == c)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_focus(NULL, c->screen, true);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win, ANY_MODIFIER);
|
|
|
|
window_setstate(c->win, XCB_WM_WITHDRAWN_STATE);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_aux_sync(globalconf.connection);
|
|
|
|
xcb_ungrab_server(globalconf.connection);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2008-03-14 16:32:58 +01:00
|
|
|
if(c->titlebar.sw)
|
2008-03-21 11:26:56 +01:00
|
|
|
simplewindow_delete(&c->titlebar.sw);
|
2008-03-14 14:27:56 +01:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
p_delete(&c);
|
|
|
|
}
|
|
|
|
|
2007-12-23 15:16:10 +01:00
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_updatewmhints(client_t *c)
|
2007-12-23 15:16:10 +01:00
|
|
|
{
|
2008-03-26 19:58:30 +01:00
|
|
|
xcb_wm_hints_t *wmh = NULL;
|
2007-12-23 15:16:10 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((wmh = xcb_get_wm_hints(globalconf.connection, c->win)))
|
2007-12-23 15:16:10 +01:00
|
|
|
{
|
2008-04-27 13:26:39 +02:00
|
|
|
const uint32_t wm_hints_flags = xcb_wm_hints_get_flags(wmh);
|
|
|
|
if((c->isurgent = ((wm_hints_flags & XCB_WM_X_URGENCY_HINT) &&
|
|
|
|
globalconf.focus->client != c)))
|
2008-04-04 10:26:46 +02:00
|
|
|
{
|
2008-01-07 19:00:17 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-04-04 10:26:46 +02:00
|
|
|
titlebar_draw(c);
|
|
|
|
}
|
2008-04-27 13:26:39 +02:00
|
|
|
if((wm_hints_flags & XCB_WM_STATE_HINT) &&
|
|
|
|
(xcb_wm_hints_get_initial_state(wmh) == XCB_WM_WITHDRAWN_STATE))
|
2008-01-14 14:18:29 +01:00
|
|
|
{
|
|
|
|
c->border = 0;
|
2008-03-21 16:50:17 +01:00
|
|
|
c->skip = true;
|
2008-01-14 14:18:29 +01:00
|
|
|
}
|
2008-04-09 16:12:15 +02:00
|
|
|
xcb_free_wm_hints(wmh);
|
2007-12-23 15:16:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_t *
|
2008-04-11 11:35:11 +02:00
|
|
|
client_updatesizehints(client_t *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
long msize;
|
2008-04-09 16:12:15 +02:00
|
|
|
xcb_size_hints_t *size = NULL;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2008-04-09 16:12:15 +02:00
|
|
|
if(!(size = xcb_get_wm_normal_hints(globalconf.connection, c->win, &msize)))
|
2008-03-21 16:50:17 +01:00
|
|
|
return NULL;
|
2008-02-01 10:42:16 +01:00
|
|
|
|
2008-04-27 13:26:39 +02:00
|
|
|
const uint32_t size_flags = xcb_size_hints_get_flags(size);
|
|
|
|
|
|
|
|
if((size_flags & XCB_SIZE_P_SIZE_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_base_size(size, &c->basew, &c->baseh);
|
2008-04-27 13:26:39 +02:00
|
|
|
else if((size_flags & XCB_SIZE_P_MIN_SIZE_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_min_size(size, &c->basew, &c->baseh);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
|
|
|
c->basew = c->baseh = 0;
|
2008-04-27 13:26:39 +02:00
|
|
|
if((size_flags & XCB_SIZE_P_RESIZE_INC_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_increase(size, &c->incw, &c->inch);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
|
|
|
c->incw = c->inch = 0;
|
|
|
|
|
2008-04-27 13:26:39 +02:00
|
|
|
if((size_flags & XCB_SIZE_P_MAX_SIZE_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_max_size(size, &c->maxw, &c->maxh);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
|
|
|
c->maxw = c->maxh = 0;
|
|
|
|
|
2008-04-27 13:26:39 +02:00
|
|
|
if((size_flags & XCB_SIZE_P_MIN_SIZE_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_min_size(size, &c->minw, &c->minh);
|
2008-04-27 13:26:39 +02:00
|
|
|
else if((size_flags & XCB_SIZE_BASE_SIZE_HINT))
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_base_size(size, &c->minw, &c->minh);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
|
|
|
c->minw = c->minh = 0;
|
|
|
|
|
2008-04-27 13:26:39 +02:00
|
|
|
if((size_flags & XCB_SIZE_P_ASPECT_HINT))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_size_hints_get_min_aspect(size, &c->minax, &c->minay);
|
|
|
|
xcb_size_hints_get_max_aspect(size, &c->maxax, &c->maxay);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
c->minax = c->maxax = c->minay = c->maxay = 0;
|
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
if(c->maxw && c->minw && c->maxh && c->minh
|
|
|
|
&& c->maxw == c->minw && c->maxh == c->minh)
|
2008-03-21 16:50:17 +01:00
|
|
|
c->isfixed = true;
|
2008-02-01 10:42:16 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
return size;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-04-28 12:23:10 +02:00
|
|
|
char *
|
|
|
|
client_markup_parse(client_t *c, const char *str, ssize_t len)
|
|
|
|
{
|
|
|
|
const char *elements[] = { "title", NULL };
|
2008-04-28 17:46:52 +02:00
|
|
|
char *title_esc = g_markup_escape_text(c->name, -1);
|
|
|
|
const char *elements_sub[] = { title_esc , NULL };
|
2008-04-28 12:23:10 +02:00
|
|
|
markup_parser_data_t *p;
|
2008-04-28 17:00:26 +02:00
|
|
|
char *ret;
|
2008-04-28 12:23:10 +02:00
|
|
|
|
|
|
|
p = markup_parser_data_new(elements, elements_sub, countof(elements));
|
|
|
|
|
2008-04-28 17:00:26 +02:00
|
|
|
if(markup_parse(p, str, len))
|
|
|
|
{
|
|
|
|
ret = p->text;
|
|
|
|
p->text = NULL;
|
|
|
|
}
|
|
|
|
else
|
2008-04-28 12:23:10 +02:00
|
|
|
return a_strdup(str);
|
|
|
|
|
2008-04-28 17:00:26 +02:00
|
|
|
markup_parser_data_delete(&p);
|
2008-04-28 17:46:52 +02:00
|
|
|
p_delete(&title_esc);
|
2008-04-28 17:00:26 +02:00
|
|
|
|
|
|
|
return ret;
|
2008-04-28 12:23:10 +02:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Set the transparency of the selected client.
|
2008-04-20 03:06:00 +02:00
|
|
|
* Argument should be an absolut or relativ floating between 0.0 and 1.0
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param screen Screen ID
|
2007-09-20 21:27:43 +02:00
|
|
|
* \param arg unused arg
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-09-05 20:15:00 +02:00
|
|
|
void
|
2007-12-17 01:17:54 +01:00
|
|
|
uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
double delta = 1.0, current_opacity = 100.0;
|
2007-09-14 13:50:46 +02:00
|
|
|
unsigned int current_opacity_raw = 0;
|
2007-09-05 20:15:00 +02:00
|
|
|
int set_prop = 0;
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_get_property_reply_t *prop_r;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
2007-10-26 23:19:13 +02:00
|
|
|
if(!sel)
|
2007-09-05 20:15:00 +02:00
|
|
|
return;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
prop_r = xcb_get_property_reply(globalconf.connection,
|
|
|
|
xcb_get_property_unchecked(globalconf.connection,
|
|
|
|
false, sel->win,
|
2008-03-26 19:58:30 +01:00
|
|
|
xutil_intern_atom(globalconf.connection, "_NET_WM_WINDOW_OPACITY"),
|
2008-03-21 16:50:17 +01:00
|
|
|
CARDINAL,
|
|
|
|
0, 1),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if(prop_r)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
memcpy(¤t_opacity_raw, xcb_get_property_value(prop_r), sizeof(unsigned int));
|
2008-04-20 03:06:01 +02:00
|
|
|
current_opacity = (double) current_opacity_raw / 0xffffffff;
|
2008-03-21 16:50:17 +01:00
|
|
|
p_delete(&prop_r);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-14 13:50:46 +02:00
|
|
|
else
|
|
|
|
set_prop = 1;
|
|
|
|
|
|
|
|
delta = compute_new_value_from_arg(arg, current_opacity);
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
if(delta <= 0.0)
|
|
|
|
delta = 0.0;
|
2008-03-31 20:07:13 +02:00
|
|
|
else if(delta > 1.0)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-03-31 20:07:13 +02:00
|
|
|
delta = 1.0;
|
2007-09-05 20:15:00 +02:00
|
|
|
set_prop = 1;
|
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
if(delta == 1.0 && !set_prop)
|
2007-12-30 15:24:51 +01:00
|
|
|
window_settrans(sel->win, -1);
|
2007-09-05 20:15:00 +02:00
|
|
|
else
|
2007-12-30 15:24:51 +01:00
|
|
|
window_settrans(sel->win, delta);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-09-18 23:36:52 +02:00
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Find a visible client on screen. Return next client or previous client if
|
|
|
|
* reverse is true.
|
|
|
|
* \param sel current selected client
|
|
|
|
* \param reverse return previous instead of next if true
|
|
|
|
* \return next or previous client
|
|
|
|
*/
|
2008-04-11 11:35:11 +02:00
|
|
|
static client_t *
|
|
|
|
client_find_visible(client_t *sel, bool reverse)
|
2008-01-12 17:01:21 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *next;
|
|
|
|
client_t *(*client_iter)(client_t **, client_t *) = client_list_next_cycle;
|
2008-01-12 17:01:21 +01:00
|
|
|
|
|
|
|
if(!sel) return NULL;
|
|
|
|
|
2008-03-14 12:19:43 +01:00
|
|
|
if(reverse)
|
|
|
|
client_iter = client_list_prev_cycle;
|
2008-01-17 14:43:15 +01:00
|
|
|
|
2008-03-14 12:19:43 +01:00
|
|
|
/* look for previous or next starting at sel */
|
2008-01-17 14:43:15 +01:00
|
|
|
|
2008-03-14 12:19:43 +01:00
|
|
|
for(next = client_iter(&globalconf.clients, sel);
|
2008-03-23 20:58:39 +01:00
|
|
|
next && next != sel && (next->skip || !client_isvisible(next, sel->screen));
|
2008-03-14 12:19:43 +01:00
|
|
|
next = client_iter(&globalconf.clients, next));
|
2008-01-17 14:43:15 +01:00
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Swap the currently focused client with the previous visible one.
|
2007-12-19 04:39:59 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg nothing
|
2007-12-19 04:26:20 +01:00
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-09-25 12:41:36 +02:00
|
|
|
void
|
2008-03-27 15:00:46 +01:00
|
|
|
uicb_client_swapprev(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
2007-09-25 12:41:36 +02:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *prev;
|
2007-09-25 12:41:36 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((prev = client_find_visible(globalconf.focus->client, true)))
|
2007-09-25 12:41:36 +02:00
|
|
|
{
|
2008-01-12 17:01:21 +01:00
|
|
|
client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[prev->screen].need_arrange = true;
|
2008-05-03 11:59:56 +02:00
|
|
|
widget_invalidate_cache(prev->screen, WIDGET_CACHE_CLIENTS);
|
2007-09-25 12:41:36 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-01 20:42:59 +02:00
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Swap the currently focused client with the next visible one.
|
2008-01-17 14:43:15 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg nothing
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-03-27 15:00:46 +01:00
|
|
|
uicb_client_swapnext(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
2008-01-17 14:43:15 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *next;
|
2008-01-17 14:43:15 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((next = client_find_visible(globalconf.focus->client, false)))
|
2008-01-17 14:43:15 +01:00
|
|
|
{
|
|
|
|
client_list_swap(&globalconf.clients, globalconf.focus->client, next);
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[next->screen].need_arrange = true;
|
2008-05-03 11:59:56 +02:00
|
|
|
widget_invalidate_cache(next->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-17 14:43:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Move and resize a client. Argument should be in format "x y w h" with
|
2008-04-10 23:37:22 +02:00
|
|
|
* absolute (1, 20, 300, ...) or relative (+10, -200, ...) values.
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg x y w h
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
2007-10-01 20:42:59 +02:00
|
|
|
void
|
2007-12-17 01:17:54 +01:00
|
|
|
uicb_client_moveresize(int screen, char *arg)
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
2008-02-28 09:23:56 +01:00
|
|
|
int ox, oy, ow, oh; /* old geometry */
|
2007-10-01 20:42:59 +02:00
|
|
|
char x[8], y[8], w[8], h[8];
|
2008-03-21 16:50:17 +01:00
|
|
|
int nmx, nmy;
|
2008-03-14 15:21:53 +01:00
|
|
|
area_t geometry;
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_query_pointer_reply_t *xqp;
|
2008-02-12 10:09:36 +01:00
|
|
|
Layout *curlay = layout_get_current(screen);
|
2007-10-01 20:42:59 +02:00
|
|
|
|
2008-02-28 07:42:16 +01:00
|
|
|
if(!sel || sel->isfixed || !arg ||
|
|
|
|
(curlay->arrange != layout_floating && !sel->isfloating))
|
|
|
|
return;
|
2008-02-12 10:08:16 +01:00
|
|
|
|
2007-10-01 20:42:59 +02:00
|
|
|
if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
|
|
|
|
return;
|
2008-02-12 10:08:16 +01:00
|
|
|
|
2008-03-14 15:21:53 +01:00
|
|
|
geometry.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
|
|
|
|
geometry.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
|
|
|
|
geometry.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
|
|
|
|
geometry.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
|
2007-10-11 23:12:05 +02:00
|
|
|
|
2008-01-05 19:38:50 +01:00
|
|
|
ox = sel->geometry.x;
|
|
|
|
oy = sel->geometry.y;
|
|
|
|
ow = sel->geometry.width;
|
|
|
|
oh = sel->geometry.height;
|
2007-10-11 23:12:05 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xqp = xcb_query_pointer_reply(globalconf.connection,
|
|
|
|
xcb_query_pointer_unchecked(globalconf.connection,
|
2008-03-27 16:05:37 +01:00
|
|
|
xcb_aux_get_screen(globalconf.connection, sel->phys_screen)->root),
|
2008-03-21 16:50:17 +01:00
|
|
|
NULL);
|
2008-03-14 15:21:53 +01:00
|
|
|
if(globalconf.screens[sel->screen].resize_hints)
|
|
|
|
geometry = client_geometry_hints(sel, geometry);
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(sel, geometry, false);
|
2008-03-30 15:46:58 +02:00
|
|
|
if (xqp)
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
2008-03-30 15:46:58 +02:00
|
|
|
if(ox <= xqp->root_x && (ox + 2 * sel->border + ow) >= xqp->root_x &&
|
|
|
|
oy <= xqp->root_y && (oy + 2 * sel->border + oh) >= xqp->root_y)
|
|
|
|
{
|
|
|
|
nmx = xqp->root_x - (ox + sel->border) + sel->geometry.width - ow;
|
|
|
|
nmy = xqp->root_y - (oy + sel->border) + sel->geometry.height - oh;
|
|
|
|
|
|
|
|
if(nmx < -sel->border) /* can happen on a resize */
|
|
|
|
nmx = -sel->border;
|
|
|
|
if(nmy < -sel->border)
|
|
|
|
nmy = -sel->border;
|
2008-03-01 12:45:59 +01:00
|
|
|
|
2008-03-30 15:46:58 +02:00
|
|
|
xcb_warp_pointer(globalconf.connection,
|
|
|
|
XCB_NONE, sel->win,
|
|
|
|
0, 0, 0, 0, nmx, nmy);
|
|
|
|
}
|
2008-03-01 12:45:59 +01:00
|
|
|
|
2008-03-30 15:46:58 +02:00
|
|
|
p_delete(&xqp);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
|
|
|
|
* supported.
|
|
|
|
* \param c the client to kill
|
|
|
|
*/
|
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-03-21 16:50:17 +01:00
|
|
|
xcb_client_message_event_t ev;
|
2007-10-01 20:42:59 +02:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(client_isprotodel(globalconf.connection, c->win))
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
2008-03-28 14:48:05 +01:00
|
|
|
/* Initialize all of event's fields first */
|
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
|
|
|
|
ev.response_type = XCB_CLIENT_MESSAGE;
|
2008-03-21 16:50:17 +01:00
|
|
|
ev.window = c->win;
|
2008-03-26 19:58:30 +01:00
|
|
|
ev.type = xutil_intern_atom(globalconf.connection, "WM_PROTOCOLS");
|
2008-03-28 14:48:05 +01:00
|
|
|
ev.format = 32;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
2008-03-26 19:58:30 +01:00
|
|
|
ev.data.data32[0] = xutil_intern_atom(globalconf.connection, "WM_DELETE_WINDOW");
|
2008-03-21 16:50:17 +01:00
|
|
|
ev.data.data32[1] = XCB_CURRENT_TIME;
|
|
|
|
|
|
|
|
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-03-31 20:07:13 +02:00
|
|
|
/** Kill the currently focused client.
|
2007-12-27 20:49:38 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2007-12-27 20:49:38 +01:00
|
|
|
|
|
|
|
if(sel)
|
|
|
|
client_kill(sel);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Maximize the client to the given geometry.
|
|
|
|
* \param c the client to maximize
|
|
|
|
* \param geometry the geometry to use for maximizing
|
|
|
|
*/
|
2008-01-06 14:40:23 +01:00
|
|
|
static void
|
2008-04-11 11:35:11 +02:00
|
|
|
client_maximize(client_t *c, area_t geometry)
|
2008-01-01 17:37:16 +01:00
|
|
|
{
|
|
|
|
if((c->ismax = !c->ismax))
|
|
|
|
{
|
2008-03-24 14:44:11 +01:00
|
|
|
/* disable titlebar */
|
|
|
|
c->titlebar.position = Off;
|
2008-01-01 17:37:16 +01:00
|
|
|
c->wasfloating = c->isfloating;
|
2008-01-06 14:40:23 +01:00
|
|
|
c->m_geometry = c->geometry;
|
2008-02-12 10:09:36 +01:00
|
|
|
if(layout_get_current(c->screen)->arrange != layout_floating)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, LAYER_FULLSCREEN);
|
|
|
|
client_focus(c, c->screen, true);
|
|
|
|
client_resize(c, geometry, false);
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
else if(c->wasfloating)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2008-03-24 14:44:11 +01:00
|
|
|
c->titlebar.position = c->titlebar.dposition;
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, LAYER_FULLSCREEN);
|
|
|
|
client_resize(c, c->m_geometry, false);
|
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-02-12 10:09:36 +01:00
|
|
|
else if(layout_get_current(c->screen)->arrange == layout_floating)
|
2008-01-11 16:38:41 +01:00
|
|
|
{
|
2008-03-24 14:44:11 +01:00
|
|
|
c->titlebar.position = c->titlebar.dposition;
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(c, c->m_geometry, false);
|
2008-01-11 16:38:41 +01:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
else
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2008-03-24 14:44:11 +01:00
|
|
|
c->titlebar.position = c->titlebar.dposition;
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, false, LAYER_TILE);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-03-24 14:44:11 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Toggle maximization state for the focused client.
|
2008-01-01 17:37:16 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area = screen_get_area(screen,
|
2008-01-01 17:37:16 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-01-01 17:37:16 +01:00
|
|
|
if(sel)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
|
|
|
area.width -= 2 * sel->border;
|
|
|
|
area.height -= 2 * sel->border;
|
|
|
|
client_maximize(sel, area);
|
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Toggle vertical maximization for the focused client.
|
2008-01-01 17:37:16 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area = screen_get_area(screen,
|
2008-01-01 17:37:16 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
|
|
|
|
|
|
|
if(sel)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
|
|
|
area.x = sel->geometry.x;
|
2008-01-12 16:04:44 +01:00
|
|
|
area.width = sel->geometry.width;
|
2008-01-06 14:40:23 +01:00
|
|
|
area.height -= 2 * sel->border;
|
|
|
|
client_maximize(sel, area);
|
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Toggle horizontal maximization for the focused client.
|
2008-01-01 17:37:16 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *sel = globalconf.focus->client;
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t area = screen_get_area(screen,
|
2008-01-01 17:37:16 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
|
|
|
|
|
|
|
if(sel)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
|
|
|
area.y = sel->geometry.y;
|
2008-01-12 16:04:44 +01:00
|
|
|
area.height = sel->geometry.height;
|
2008-01-06 14:40:23 +01:00
|
|
|
area.width -= 2 * sel->border;
|
|
|
|
client_maximize(sel, area);
|
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Move the client to the master area.
|
2008-01-01 17:37:16 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c, *sel = globalconf.focus->client;
|
2008-01-01 17:37:16 +01:00
|
|
|
|
2008-02-05 07:15:23 +01:00
|
|
|
if(!sel)
|
|
|
|
return;
|
|
|
|
|
2008-01-07 19:07:22 +01:00
|
|
|
for(c = globalconf.clients; !client_isvisible(c, screen); c = c->next);
|
|
|
|
if(c == sel)
|
2008-01-01 17:37:16 +01:00
|
|
|
for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
|
|
|
|
|
2008-02-05 07:15:23 +01:00
|
|
|
if(sel)
|
|
|
|
{
|
|
|
|
client_list_detach(&globalconf.clients, sel);
|
|
|
|
client_list_push(&globalconf.clients, sel);
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[screen].need_arrange = true;
|
2008-02-05 07:15:23 +01:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Give focus to the next visible client in the stack.
|
2008-01-17 14:16:45 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *next;
|
2008-01-17 14:16:45 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((next = client_find_visible(globalconf.focus->client, false)))
|
|
|
|
client_focus(next, screen, true);
|
2008-01-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Give focus to the previous visible client in the stack.
|
2008-01-17 14:16:45 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *prev;
|
2008-01-17 14:16:45 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if((prev = client_find_visible(globalconf.focus->client, true)))
|
|
|
|
client_focus(prev, screen, true);
|
2008-01-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Toggle the floating state of the focused client.
|
2008-01-17 14:16:45 +01:00
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-03-27 15:00:46 +01:00
|
|
|
uicb_client_togglefloating(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
2008-01-17 14:16:45 +01:00
|
|
|
{
|
2008-01-24 20:07:17 +01:00
|
|
|
if(globalconf.focus->client)
|
2008-04-08 19:52:59 +02:00
|
|
|
client_setfloating(globalconf.focus->client, !globalconf.focus->client->isfloating,
|
|
|
|
globalconf.focus->client->layer == LAYER_FLOAT ? LAYER_TILE : LAYER_FLOAT);
|
2008-01-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:07:13 +02:00
|
|
|
/** Toggle the scratch client attribute on the focused client.
|
2008-02-06 08:49:31 +01:00
|
|
|
* \param screen screen number
|
|
|
|
* \param arg unused argument
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-03-27 15:00:46 +01:00
|
|
|
uicb_client_setscratch(int screen, char *arg __attribute__ ((unused)))
|
2008-02-06 08:49:31 +01:00
|
|
|
{
|
|
|
|
if(!globalconf.focus->client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(globalconf.scratch.client == globalconf.focus->client)
|
|
|
|
globalconf.scratch.client = NULL;
|
|
|
|
else
|
|
|
|
globalconf.scratch.client = globalconf.focus->client;
|
|
|
|
|
|
|
|
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS | WIDGET_CACHE_TAGS);
|
2008-03-21 16:50:17 +01:00
|
|
|
globalconf.screens[screen].need_arrange = true;
|
2008-02-06 08:49:31 +01:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:37:22 +02:00
|
|
|
/** Toggle the scratch client's visibility.
|
2008-02-06 08:49:31 +01:00
|
|
|
* \param screen screen number
|
|
|
|
* \param arg unused argument
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-03-27 15:00:46 +01:00
|
|
|
uicb_client_togglescratch(int screen, char *arg __attribute__ ((unused)))
|
2008-02-06 08:49:31 +01:00
|
|
|
{
|
|
|
|
if(globalconf.scratch.client)
|
|
|
|
{
|
|
|
|
globalconf.scratch.isvisible = !globalconf.scratch.isvisible;
|
2008-02-08 15:08:42 +01:00
|
|
|
if(globalconf.scratch.isvisible)
|
2008-03-21 16:50:17 +01:00
|
|
|
client_focus(globalconf.scratch.client, screen, true);
|
|
|
|
globalconf.screens[globalconf.scratch.client->screen].need_arrange = true;
|
2008-02-06 08:49:31 +01:00
|
|
|
widget_invalidate_cache(globalconf.scratch.client->screen, WIDGET_CACHE_CLIENTS);
|
|
|
|
}
|
|
|
|
}
|
2008-03-15 13:59:04 +01:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|