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>
|
|
|
|
#include <X11/Xatom.h>
|
2007-09-13 15:57:35 +02:00
|
|
|
#include <X11/extensions/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-01 18:02:36 +01:00
|
|
|
#include "screen.h"
|
2008-01-07 18:12:38 +01:00
|
|
|
#include "widget.h"
|
2008-01-27 19:08:11 +01:00
|
|
|
#include "xutil.h"
|
2007-09-05 20:15:00 +02:00
|
|
|
#include "layouts/floating.h"
|
|
|
|
|
2007-12-16 02:45:38 +01: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
|
|
|
|
* \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
|
|
|
*/
|
2007-12-14 14:29:32 +01:00
|
|
|
static Bool
|
2007-12-16 02:45:38 +01:00
|
|
|
client_loadprops(Client * c, int screen)
|
2007-10-16 22:40:02 +02:00
|
|
|
{
|
2007-12-14 19:02:38 +01:00
|
|
|
int i, ntags = 0;
|
|
|
|
Tag *tag;
|
2007-12-14 14:29:32 +01:00
|
|
|
char *prop;
|
|
|
|
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
|
|
|
|
2007-12-14 19:02:38 +01:00
|
|
|
prop = p_new(char, ntags + 2);
|
|
|
|
|
2008-01-06 22:55:46 +01:00
|
|
|
if(xgettextprop(c->win,
|
|
|
|
XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
|
|
|
|
prop, ntags + 2))
|
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);
|
2007-12-14 14:29:32 +01:00
|
|
|
result = True;
|
|
|
|
}
|
|
|
|
else
|
2007-12-27 22:43:59 +01:00
|
|
|
untag_client(c, tag);
|
2007-12-14 14:29:32 +01:00
|
|
|
|
2007-12-14 19:02:38 +01:00
|
|
|
if(i <= ntags && prop[i])
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, prop[i] == '1');
|
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
|
2007-09-11 13:14:43 +02:00
|
|
|
* \return True if client has WM_DELETE_WINDOW
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
|
|
|
static Bool
|
2008-01-29 08:21:05 +01:00
|
|
|
client_isprotodel(Display *disp, Window win)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
int i, n;
|
|
|
|
Atom *protocols;
|
|
|
|
Bool ret = False;
|
|
|
|
|
2007-10-19 15:36:41 +02:00
|
|
|
if(XGetWMProtocols(disp, win, &protocols, &n))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
for(i = 0; !ret && i < n; i++)
|
2007-10-19 15:36:41 +02:00
|
|
|
if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
|
2007-09-05 20:15:00 +02:00
|
|
|
ret = True;
|
|
|
|
XFree(protocols);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-14 14:29:32 +01:00
|
|
|
/** Get a Client by its window
|
|
|
|
* \param list Client list to look info
|
|
|
|
* \param w Client window to find
|
|
|
|
* \return client
|
|
|
|
*/
|
|
|
|
Client *
|
2008-01-29 08:21:05 +01:00
|
|
|
client_get_bywin(Client *list, Window w)
|
2007-12-14 14:29:32 +01:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
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
|
|
|
|
* \param list Client list
|
|
|
|
* \param name name to search
|
|
|
|
* \return first matching client
|
|
|
|
*/
|
2007-12-23 16:16:02 +01:00
|
|
|
Client *
|
2008-01-29 08:21:05 +01:00
|
|
|
client_get_byname(Client *list, char *name)
|
2007-12-23 16:16:02 +01:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
|
|
|
|
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
|
2007-12-14 16:05:10 +01:00
|
|
|
client_updatetitle(Client *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-06 22:53:40 +01:00
|
|
|
if(!xgettextprop(c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
|
|
|
|
xgettextprop(c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
|
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
|
|
|
|
client_unfocus(Client *c)
|
|
|
|
{
|
|
|
|
XSetWindowBorder(globalconf.display, c->win,
|
|
|
|
globalconf.screens[c->screen].colors_normal[ColBorder].pixel);
|
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-25 22:50:18 +01:00
|
|
|
focus_add_client(NULL);
|
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-01-25 12:55:44 +01:00
|
|
|
client_ban(Client *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);
|
2007-12-27 23:10:43 +01:00
|
|
|
XUnmapWindow(globalconf.display, c->win);
|
2007-12-30 15:24:51 +01:00
|
|
|
window_setstate(c->win, IconicState);
|
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
|
2007-09-05 20:15:00 +02:00
|
|
|
*/
|
|
|
|
void
|
2008-01-27 19:07:39 +01:00
|
|
|
client_focus(Client *c, int screen, Bool from_mouse)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-02 19:26:55 +01:00
|
|
|
int phys_screen = get_phys_screen(screen);
|
|
|
|
|
2007-12-28 10:12:34 +01:00
|
|
|
/* if c is NULL or invisible, take next client in the focus history */
|
2008-01-24 23:48:35 +01:00
|
|
|
if(!c || (c && !client_isvisible(c, screen)))
|
2007-12-28 10:12:34 +01:00
|
|
|
{
|
|
|
|
c = focus_get_current_client(screen);
|
|
|
|
/* if c is still NULL take next client in the stack */
|
|
|
|
if(!c)
|
2007-12-28 14:12:54 +01:00
|
|
|
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
|
2007-12-28 10:12:34 +01:00
|
|
|
}
|
2007-10-03 17:26:14 +02: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-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-01-25 12:55:44 +01:00
|
|
|
XSetWindowBorder(globalconf.display, c->win,
|
|
|
|
globalconf.screens[screen].colors_selected[ColBorder].pixel);
|
|
|
|
XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
|
2008-01-25 23:43:16 +01:00
|
|
|
if(!from_mouse
|
|
|
|
|| !globalconf.screens[screen].sloppy_focus
|
|
|
|
|| globalconf.screens[screen].sloppy_focus_raise)
|
|
|
|
XRaiseWindow(globalconf.display, c->win);
|
2008-01-26 13:11:12 +01:00
|
|
|
/* since we're dropping EnterWindow events and sometimes the window
|
|
|
|
* will appear under the mouse, grabbuttons */
|
|
|
|
window_grabbuttons(phys_screen, c->win);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else
|
2007-12-16 02:45:38 +01:00
|
|
|
XSetInputFocus(globalconf.display,
|
2008-01-02 19:26:55 +01:00
|
|
|
RootWindow(globalconf.display, phys_screen),
|
2007-12-14 21:51:54 +01:00
|
|
|
RevertToPointerRoot, CurrentTime);
|
2007-12-28 13:43:47 +01:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
|
2008-01-02 19:26:55 +01:00
|
|
|
ewmh_update_net_active_window(phys_screen);
|
2008-01-25 12:55:44 +01:00
|
|
|
globalconf.drop_events |= EnterWindowMask;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-01-28 18:30:23 +01:00
|
|
|
/** Compute smart coordinates for a client window
|
|
|
|
* \param geometry current/requested client geometry
|
|
|
|
* \param screen screen used
|
|
|
|
* \return new geometry
|
|
|
|
*/
|
|
|
|
static Area
|
2008-01-29 09:13:35 +01:00
|
|
|
client_get_smart_geometry(Area geometry, int border, int screen)
|
2008-01-28 18:30:23 +01:00
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
Area newgeometry = { 0, 0, 0, 0, NULL };
|
|
|
|
Area *screen_geometry, *arealist = NULL, *r;
|
2008-01-29 09:13:35 +01:00
|
|
|
Bool found = False;
|
2008-01-28 18:30:23 +01:00
|
|
|
|
|
|
|
screen_geometry = p_new(Area, 1);
|
|
|
|
|
2008-01-29 19:06:44 +01:00
|
|
|
*screen_geometry = screen_get_area(screen,
|
2008-01-28 18:30:23 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
|
|
|
|
|
|
|
area_list_push(&arealist, screen_geometry);
|
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
|
|
|
if(client_isvisible(c, screen))
|
2008-01-28 20:16:54 +01:00
|
|
|
{
|
|
|
|
newgeometry = c->f_geometry;
|
|
|
|
newgeometry.width += 2 * c->border;
|
|
|
|
newgeometry.height += 2 * c->border;
|
|
|
|
area_list_remove(&arealist, &newgeometry);
|
|
|
|
}
|
2008-01-28 18:30:23 +01:00
|
|
|
|
|
|
|
newgeometry.x = geometry.x;
|
|
|
|
newgeometry.y = geometry.y;
|
2008-01-28 20:16:54 +01:00
|
|
|
newgeometry.width = 0;
|
|
|
|
newgeometry.height = 0;
|
2008-01-28 18:30:23 +01:00
|
|
|
|
|
|
|
for(r = arealist; r; r = r->next)
|
|
|
|
if(r->width >= geometry.width && r->height >= geometry.height
|
|
|
|
&& r->width * r->height > newgeometry.width * newgeometry.height)
|
2008-01-29 09:13:35 +01:00
|
|
|
{
|
|
|
|
found = True;
|
2008-01-28 18:30:23 +01:00
|
|
|
newgeometry = *r;
|
2008-01-29 09:13:35 +01:00
|
|
|
}
|
2008-01-28 18:30:23 +01:00
|
|
|
|
2008-01-29 09:13:35 +01:00
|
|
|
/* we did not found a space with enough space for our size:
|
|
|
|
* just take the biggest available and go in */
|
|
|
|
if(!found)
|
|
|
|
for(r = arealist; r; r = r->next)
|
|
|
|
if(r->width * r->height > newgeometry.width * newgeometry.height)
|
|
|
|
newgeometry = *r;
|
2008-01-28 18:30:23 +01:00
|
|
|
|
|
|
|
/* restore height and width */
|
|
|
|
newgeometry.width = geometry.width;
|
|
|
|
newgeometry.height = geometry.height;
|
|
|
|
|
2008-01-29 09:13:35 +01:00
|
|
|
/* fix offscreen */
|
|
|
|
if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry))
|
|
|
|
newgeometry.x = screen_geometry->x + screen_geometry->width - newgeometry.width - 2 * border;
|
|
|
|
|
|
|
|
if(AREA_BOTTOM(newgeometry) > AREA_BOTTOM(*screen_geometry))
|
|
|
|
newgeometry.y = screen_geometry->y + screen_geometry->height - newgeometry.height - 2 * border;
|
|
|
|
|
|
|
|
area_list_wipe(&arealist);
|
|
|
|
|
2008-01-28 18:30:23 +01:00
|
|
|
return newgeometry;
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:27:43 +02:00
|
|
|
/** Manage a new client
|
|
|
|
* \param w The window
|
|
|
|
* \param wa Window attributes
|
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
|
2007-12-16 02:45:38 +01:00
|
|
|
client_manage(Window w, XWindowAttributes *wa, int screen)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
Client *c, *t = NULL;
|
|
|
|
Window trans;
|
2008-01-07 18:57:25 +01:00
|
|
|
Bool rettrans;
|
2007-09-05 20:15:00 +02:00
|
|
|
XWindowChanges wc;
|
2007-12-14 19:02:38 +01:00
|
|
|
Tag *tag;
|
2008-01-02 12:00:36 +01:00
|
|
|
Rule *rule;
|
2008-01-22 09:50:24 +01:00
|
|
|
Area screen_geom;
|
2008-01-02 19:26:55 +01:00
|
|
|
int phys_screen = get_phys_screen(screen);
|
2008-02-01 10:42:16 +01:00
|
|
|
long flags;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
c = p_new(Client, 1);
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-01-29 19:06:44 +01:00
|
|
|
c->screen = screen_get_bycoord(wa->x, wa->y);
|
2008-01-22 09:50:24 +01:00
|
|
|
|
2008-01-29 19:06:44 +01:00
|
|
|
screen_geom = screen_get_area(c->screen,
|
2008-01-28 11:43:37 +01:00
|
|
|
globalconf.screens[screen].statusbar,
|
|
|
|
&globalconf.screens[screen].padding);
|
2008-01-13 16:30:43 +01:00
|
|
|
/* Initial values */
|
2007-09-05 20:15:00 +02:00
|
|
|
c->win = w;
|
2008-01-22 09:50:24 +01:00
|
|
|
c->geometry.x = c->f_geometry.x = c->m_geometry.x = MAX(wa->x, screen_geom.x);
|
|
|
|
c->geometry.y = c->f_geometry.y = c->m_geometry.y = MAX(wa->y, screen_geom.y);
|
2008-01-05 19:38:50 +01:00
|
|
|
c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
|
|
|
|
c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
|
2007-09-05 20:15:00 +02:00
|
|
|
c->oldborder = wa->border_width;
|
2008-01-16 19:01:30 +01:00
|
|
|
c->newcomer = True;
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
c->border = globalconf.screens[screen].borderpx;
|
2007-11-15 14:44:43 +01:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* Set windows borders */
|
|
|
|
wc.border_width = c->border;
|
|
|
|
XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
|
|
|
|
XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
|
|
|
|
/* 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-02-01 10:42:16 +01:00
|
|
|
flags = client_updatesizehints(c);
|
2008-01-13 16:30:43 +01:00
|
|
|
client_updatewmhints(c);
|
2007-12-28 20:48:29 +01:00
|
|
|
|
2008-01-13 16:30:43 +01:00
|
|
|
/* First check clients hints */
|
2007-12-28 20:48:29 +01:00
|
|
|
ewmh_check_client_hints(c);
|
2008-01-13 16:30:43 +01:00
|
|
|
|
2007-11-13 22:41:56 +01:00
|
|
|
/* loadprops or apply rules if no props */
|
2007-12-16 02:45:38 +01:00
|
|
|
if(!client_loadprops(c, screen))
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-13 16:30:43 +01:00
|
|
|
/* Get the client's rule */
|
|
|
|
if((rule = rule_matching_client(c)))
|
|
|
|
{
|
|
|
|
if(rule->screen != RULE_NOSCREEN)
|
|
|
|
move_client_to_screen(c, rule->screen, True);
|
|
|
|
else
|
|
|
|
move_client_to_screen(c, screen, True);
|
2008-01-13 18:22:05 +01:00
|
|
|
tag_client_with_rule(c, rule);
|
2008-01-13 18:32:25 +01:00
|
|
|
|
|
|
|
switch(rule->isfloating)
|
|
|
|
{
|
|
|
|
case Auto:
|
|
|
|
break;
|
|
|
|
case Float:
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
2008-01-13 18:32:25 +01:00
|
|
|
break;
|
|
|
|
case Tile:
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, False);
|
2008-01-13 18:32:25 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-01-25 23:48:24 +01:00
|
|
|
|
|
|
|
if(rule->opacity >= 0.0f)
|
|
|
|
window_settrans(c->win, rule->opacity);
|
2008-01-13 16:30:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
move_client_to_screen(c, screen, True);
|
|
|
|
/* check for transient and set tags like its parent,
|
|
|
|
* XGetTransientForHint returns 1 on success
|
|
|
|
*/
|
|
|
|
if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
|
2008-01-29 08:21:05 +01:00
|
|
|
&& (t = client_get_bywin(globalconf.clients, trans)))
|
2008-01-13 16:30:43 +01:00
|
|
|
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 */
|
|
|
|
if(!c->isfloating)
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, rettrans || c->isfixed);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2007-10-22 16:25:27 +02:00
|
|
|
|
2008-02-01 10:42:16 +01:00
|
|
|
if(!(flags & (USSize | PSize)))
|
|
|
|
c->f_geometry = client_get_smart_geometry(c->f_geometry, c->border, c->screen);
|
2008-01-28 18:30:23 +01:00
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
|
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
|
|
|
{
|
2007-12-27 23:10:43 +01:00
|
|
|
XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
|
2008-01-02 19:26:55 +01:00
|
|
|
window_setshape(phys_screen, c->win);
|
2007-09-13 15:57:35 +02:00
|
|
|
}
|
2007-10-22 16:25:27 +02:00
|
|
|
|
|
|
|
/* attach to the stack */
|
2008-01-12 22:59:13 +01:00
|
|
|
if((rule = rule_matching_client(c)) && rule->not_master)
|
|
|
|
client_list_append(&globalconf.clients, c);
|
|
|
|
else 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
|
|
|
|
|
|
|
/* some windows require this */
|
2008-01-05 19:38:50 +01:00
|
|
|
XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
|
|
|
|
c->geometry.width, c->geometry.height);
|
2008-01-13 16:30:43 +01:00
|
|
|
|
2008-01-11 16:44:24 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-13 16:30:43 +01:00
|
|
|
ewmh_update_net_client_list(phys_screen);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
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
|
2007-12-30 15:08:38 +01:00
|
|
|
* \param sizehints respect size hints
|
2008-01-06 14:40:23 +01:00
|
|
|
* \param return True if resize has been done
|
2007-12-30 15:08:38 +01:00
|
|
|
*/
|
2008-01-06 14:40:23 +01:00
|
|
|
Bool
|
|
|
|
client_resize(Client *c, Area geometry, Bool sizehints)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-06 14:40:23 +01:00
|
|
|
int new_screen;
|
2007-09-05 20:15:00 +02:00
|
|
|
double dx, dy, max, min, ratio;
|
2007-12-23 00:54:59 +01:00
|
|
|
Area area;
|
2008-01-06 14:40:23 +01:00
|
|
|
XWindowChanges wc;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
if(sizehints)
|
|
|
|
{
|
2008-01-05 20:18:30 +01:00
|
|
|
if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
|
|
|
|
&& (geometry.width - c->basew) > 0)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2008-01-05 20:18:30 +01:00
|
|
|
dx = (double) (geometry.width - c->basew);
|
|
|
|
dy = (double) (geometry.height - c->baseh);
|
2007-09-05 20:15:00 +02:00
|
|
|
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;
|
2008-01-05 20:18:30 +01:00
|
|
|
geometry.width = (int) dx + c->basew;
|
|
|
|
geometry.height = (int) dy + c->baseh;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
else if(ratio > max)
|
|
|
|
{
|
|
|
|
dy = (dx * min + dy) / (max * max + 1);
|
|
|
|
dx = dy * min;
|
2008-01-05 20:18:30 +01:00
|
|
|
geometry.width = (int) dx + c->basew;
|
|
|
|
geometry.height = (int) dy + c->baseh;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-05 20:18:30 +01:00
|
|
|
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;
|
2007-09-05 20:15:00 +02:00
|
|
|
if(c->incw)
|
2008-01-05 20:18:30 +01:00
|
|
|
geometry.width -= (geometry.width - c->basew) % c->incw;
|
2007-09-05 20:15:00 +02:00
|
|
|
if(c->inch)
|
2008-01-05 20:18:30 +01:00
|
|
|
geometry.height -= (geometry.height - c->baseh) % c->inch;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-01-05 20:18:30 +01:00
|
|
|
if(geometry.width <= 0 || geometry.height <= 0)
|
2008-01-06 14:40:23 +01:00
|
|
|
return False;
|
2007-09-05 20:15:00 +02:00
|
|
|
/* offscreen appearance fixes */
|
2008-01-02 19:26:55 +01:00
|
|
|
area = get_display_area(get_phys_screen(c->screen),
|
2007-12-23 00:54:59 +01:00
|
|
|
NULL,
|
|
|
|
&globalconf.screens[c->screen].padding);
|
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-01-29 19:06:44 +01:00
|
|
|
new_screen = screen_get_bycoord(geometry.x, geometry.y);
|
2008-01-06 14:40:23 +01:00
|
|
|
|
|
|
|
c->geometry.x = wc.x = geometry.x;
|
|
|
|
c->geometry.y = wc.y = geometry.y;
|
|
|
|
c->geometry.width = wc.width = geometry.width;
|
|
|
|
c->geometry.height = wc.height = geometry.height;
|
|
|
|
wc.border_width = c->border;
|
|
|
|
|
2008-01-11 17:54:48 +01:00
|
|
|
/* save the floating geometry if the window is floating but not
|
|
|
|
* maximized */
|
|
|
|
if((c->isfloating ||
|
|
|
|
get_current_layout(new_screen)->arrange == layout_floating) && !c->ismax)
|
2008-01-06 14:40:23 +01:00
|
|
|
c->f_geometry = geometry;
|
|
|
|
|
|
|
|
XConfigureWindow(globalconf.display, c->win,
|
|
|
|
CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
|
|
|
|
window_configure(c->win, geometry, c->border);
|
|
|
|
|
|
|
|
if(c->screen != new_screen)
|
|
|
|
move_client_to_screen(c, new_screen, False);
|
|
|
|
|
|
|
|
return True;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
2008-01-06 14:40:23 +01:00
|
|
|
return False;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2008-01-17 10:40:39 +01:00
|
|
|
void
|
|
|
|
client_setfloating(Client *c, Bool floating)
|
|
|
|
{
|
|
|
|
if(c->isfloating != floating)
|
2008-01-17 19:17:53 +01:00
|
|
|
{
|
2008-01-17 10:40:39 +01:00
|
|
|
if((c->isfloating = floating))
|
|
|
|
client_resize(c, c->f_geometry, False);
|
2008-01-24 20:07:17 +01:00
|
|
|
else if(c->ismax)
|
|
|
|
{
|
|
|
|
c->ismax = False;
|
|
|
|
client_resize(c, c->m_geometry, False);
|
|
|
|
}
|
2008-01-18 09:34:52 +01:00
|
|
|
if(client_isvisible(c, c->screen))
|
|
|
|
globalconf.screens[c->screen].need_arrange = True;
|
2008-01-17 19:17:53 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
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
|
2007-12-30 15:08:38 +01:00
|
|
|
client_saveprops(Client *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;
|
2007-12-14 19:02:38 +01:00
|
|
|
Tag *tag;
|
|
|
|
|
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
|
|
|
|
2007-12-14 19:02:38 +01:00
|
|
|
prop = p_new(char, ntags + 2);
|
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
|
|
|
|
2007-12-14 19:02:38 +01:00
|
|
|
if(i <= ntags)
|
2007-09-07 11:18:27 +02:00
|
|
|
prop[i] = c->isfloating ? '1' : '0';
|
|
|
|
|
|
|
|
prop[++i] = '\0';
|
|
|
|
|
2008-01-06 22:55:46 +01:00
|
|
|
XChangeProperty(globalconf.display, c->win,
|
|
|
|
XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
|
|
|
|
XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
|
2007-09-07 11:18:27 +02:00
|
|
|
|
|
|
|
p_delete(&prop);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-10-26 19:50:39 +02:00
|
|
|
client_unban(Client *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-12-27 23:10:43 +01:00
|
|
|
XMapWindow(globalconf.display, c->win);
|
2007-12-30 15:24:51 +01:00
|
|
|
window_setstate(c->win, NormalState);
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-06 21:57:53 +01:00
|
|
|
client_unmanage(Client *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
XWindowChanges wc;
|
2007-12-14 19:02:38 +01:00
|
|
|
Tag *tag;
|
2007-09-05 20:15:00 +02:00
|
|
|
|
|
|
|
wc.border_width = c->oldborder;
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
/* The server grab construct avoids race conditions. */
|
2007-12-27 23:10:43 +01:00
|
|
|
XGrabServer(globalconf.display);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
|
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);
|
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-01-27 19:07:39 +01:00
|
|
|
client_focus(NULL, c->screen, False);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
|
2008-01-06 21:57:53 +01:00
|
|
|
window_setstate(c->win, WithdrawnState);
|
|
|
|
|
2007-12-27 23:10:43 +01:00
|
|
|
XSync(globalconf.display, False);
|
|
|
|
XUngrabServer(globalconf.display);
|
2008-01-06 21:57:53 +01:00
|
|
|
|
2007-09-05 20:15:00 +02:00
|
|
|
p_delete(&c);
|
|
|
|
}
|
|
|
|
|
2007-12-23 15:16:10 +01:00
|
|
|
void
|
|
|
|
client_updatewmhints(Client *c)
|
|
|
|
{
|
|
|
|
XWMHints *wmh;
|
|
|
|
|
|
|
|
if((wmh = XGetWMHints(globalconf.display, c->win)))
|
|
|
|
{
|
2008-01-07 19:00:17 +01:00
|
|
|
if((c->isurgent = (wmh->flags & XUrgencyHint)))
|
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2007-12-30 18:24:21 +01:00
|
|
|
if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
|
2008-01-14 14:18:29 +01:00
|
|
|
{
|
|
|
|
c->border = 0;
|
2007-12-28 20:48:29 +01:00
|
|
|
c->skip = True;
|
2008-01-14 14:18:29 +01:00
|
|
|
}
|
2007-12-23 15:16:10 +01:00
|
|
|
XFree(wmh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 10:42:16 +01:00
|
|
|
long
|
2007-12-14 16:05:10 +01:00
|
|
|
client_updatesizehints(Client *c)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
long msize;
|
|
|
|
XSizeHints size;
|
|
|
|
|
2008-02-01 10:42:16 +01:00
|
|
|
if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize))
|
|
|
|
return 0L;
|
|
|
|
|
2008-01-05 18:57:33 +01:00
|
|
|
if(size.flags & PBaseSize)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->basew = size.base_width;
|
|
|
|
c->baseh = size.base_height;
|
|
|
|
}
|
2008-01-05 18:57:33 +01:00
|
|
|
else if(size.flags & PMinSize)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->basew = size.min_width;
|
|
|
|
c->baseh = size.min_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c->basew = c->baseh = 0;
|
2008-01-05 18:57:33 +01:00
|
|
|
if(size.flags & PResizeInc)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->incw = size.width_inc;
|
|
|
|
c->inch = size.height_inc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c->incw = c->inch = 0;
|
|
|
|
|
2008-01-05 18:57:33 +01:00
|
|
|
if(size.flags & PMaxSize)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->maxw = size.max_width;
|
|
|
|
c->maxh = size.max_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c->maxw = c->maxh = 0;
|
|
|
|
|
2008-01-05 18:57:33 +01:00
|
|
|
if(size.flags & PMinSize)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->minw = size.min_width;
|
|
|
|
c->minh = size.min_height;
|
|
|
|
}
|
2008-01-05 18:57:33 +01:00
|
|
|
else if(size.flags & PBaseSize)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->minw = size.base_width;
|
|
|
|
c->minh = size.base_height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c->minw = c->minh = 0;
|
|
|
|
|
2008-01-05 18:57:33 +01:00
|
|
|
if(size.flags & PAspect)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
|
|
|
c->minax = size.min_aspect.x;
|
|
|
|
c->maxax = size.max_aspect.x;
|
|
|
|
c->minay = size.min_aspect.y;
|
|
|
|
c->maxay = size.max_aspect.y;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
c->isfixed = True;
|
2008-02-01 10:42:16 +01:00
|
|
|
|
|
|
|
return size.flags;
|
2007-09-05 20:15:00 +02:00
|
|
|
}
|
|
|
|
|
2007-12-14 16:38:12 +01:00
|
|
|
/** Returns True if a client is tagged
|
|
|
|
* with one of the tags
|
|
|
|
* \return True or False
|
|
|
|
*/
|
|
|
|
Bool
|
2007-12-16 02:45:38 +01:00
|
|
|
client_isvisible(Client *c, int screen)
|
2007-12-14 16:38:12 +01:00
|
|
|
{
|
2007-12-14 19:02:38 +01:00
|
|
|
Tag *tag;
|
2007-12-14 16:38:12 +01:00
|
|
|
|
2008-01-10 07:04:51 +01:00
|
|
|
if(!c || c->screen != screen)
|
2007-12-14 16:38:12 +01:00
|
|
|
return False;
|
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
|
2007-12-27 23:05:34 +01:00
|
|
|
if(tag->selected && is_client_tagged(c, tag))
|
2007-12-14 16:38:12 +01:00
|
|
|
return True;
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
2007-09-20 21:27:43 +02:00
|
|
|
/** Set selected client transparency
|
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
|
|
|
{
|
2007-10-09 23:47:45 +02:00
|
|
|
double delta = 100.0, current_opacity = 100.0;
|
2007-09-05 20:15:00 +02:00
|
|
|
unsigned char *data;
|
|
|
|
Atom actual;
|
|
|
|
int format;
|
|
|
|
unsigned long n, left;
|
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;
|
2007-12-16 02:45:38 +01:00
|
|
|
Client *sel = globalconf.focus->client;
|
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;
|
|
|
|
|
2007-12-16 02:45:38 +01:00
|
|
|
XGetWindowProperty(globalconf.display, sel->win,
|
2007-12-27 23:10:43 +01:00
|
|
|
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
|
2007-09-14 13:50:46 +02:00
|
|
|
0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
|
|
|
|
(unsigned char **) &data);
|
|
|
|
if(data)
|
2007-09-05 20:15:00 +02:00
|
|
|
{
|
2007-09-14 13:50:46 +02:00
|
|
|
memcpy(¤t_opacity_raw, data, sizeof(unsigned int));
|
|
|
|
XFree(data);
|
|
|
|
current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
|
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;
|
|
|
|
else if(delta > 100.0)
|
|
|
|
{
|
|
|
|
delta = 100.0;
|
|
|
|
set_prop = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(delta == 100.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-01-17 14:43:15 +01:00
|
|
|
static Client *
|
2008-01-12 17:01:21 +01:00
|
|
|
client_find_prev_visible(Client *sel)
|
|
|
|
{
|
|
|
|
Client *prev = NULL;
|
|
|
|
|
|
|
|
if(!sel) return NULL;
|
|
|
|
|
|
|
|
/* look for previous starting at sel */
|
2008-01-12 22:30:19 +01:00
|
|
|
for(prev = client_list_prev_cycle(&globalconf.clients, sel);
|
2008-01-12 17:01:21 +01:00
|
|
|
prev && (prev->skip || !client_isvisible(prev, sel->screen));
|
2008-01-12 22:30:19 +01:00
|
|
|
prev = client_list_prev_cycle(&globalconf.clients, prev));
|
2008-01-12 17:01:21 +01:00
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
2008-01-17 14:43:15 +01:00
|
|
|
static Client *
|
|
|
|
client_find_next_visible(Client *sel)
|
|
|
|
{
|
|
|
|
Client *next = NULL;
|
|
|
|
|
|
|
|
if(!sel) return NULL;
|
|
|
|
|
|
|
|
for(next = sel->next; next && !client_isvisible(next, sel->screen); next = next->next);
|
|
|
|
if(!next)
|
|
|
|
for(next = globalconf.clients; next && !client_isvisible(next, sel->screen); next = next->next);
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
2007-12-19 04:26:20 +01:00
|
|
|
/** Swap current with previous client
|
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-01-17 19:17:53 +01:00
|
|
|
uicb_client_swapprev(int screen __attribute__ ((unused)),
|
|
|
|
char *arg __attribute__ ((unused)))
|
2007-09-25 12:41:36 +02:00
|
|
|
{
|
2008-01-12 17:01:21 +01:00
|
|
|
Client *prev;
|
2007-09-25 12:41:36 +02:00
|
|
|
|
2008-01-12 17:01:21 +01:00
|
|
|
if((prev = client_find_prev_visible(globalconf.focus->client)))
|
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-01-17 19:17:53 +01:00
|
|
|
globalconf.screens[prev->screen].need_arrange = True;
|
2008-01-28 16:46:31 +01:00
|
|
|
globalconf.drop_events |= EnterWindowMask;
|
2007-09-25 12:41:36 +02:00
|
|
|
}
|
|
|
|
}
|
2007-10-01 20:42:59 +02:00
|
|
|
|
2008-01-17 14:43:15 +01:00
|
|
|
/** Swap current with next client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg nothing
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-01-17 19:17:53 +01:00
|
|
|
uicb_client_swapnext(int screen __attribute__ ((unused)),
|
|
|
|
char *arg __attribute__ ((unused)))
|
2008-01-17 14:43:15 +01:00
|
|
|
{
|
|
|
|
Client *next;
|
|
|
|
|
|
|
|
if((next = client_find_next_visible(globalconf.focus->client)))
|
|
|
|
{
|
|
|
|
client_list_swap(&globalconf.clients, globalconf.focus->client, next);
|
2008-01-17 19:17:53 +01:00
|
|
|
globalconf.screens[next->screen].need_arrange = True;
|
2008-01-28 16:46:31 +01:00
|
|
|
globalconf.drop_events |= EnterWindowMask;
|
2008-01-17 14:43:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-19 04:26:20 +01:00
|
|
|
/** Move and resize client
|
|
|
|
* \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-01-05 20:18:30 +01:00
|
|
|
int ox, oy, ow, oh;
|
2007-10-01 20:42:59 +02:00
|
|
|
char x[8], y[8], w[8], h[8];
|
|
|
|
int mx, my, dx, dy, nmx, nmy;
|
|
|
|
unsigned int dui;
|
|
|
|
Window dummy;
|
2008-01-05 20:18:30 +01:00
|
|
|
Area area;
|
2007-12-16 02:45:38 +01:00
|
|
|
Client *sel = globalconf.focus->client;
|
2008-01-29 08:31:13 +01:00
|
|
|
Tag **curtags = tags_get_current(screen);
|
2007-10-01 20:42:59 +02:00
|
|
|
|
2007-12-27 13:22:40 +01:00
|
|
|
if(curtags[0]->layout->arrange != layout_floating)
|
2007-10-26 23:19:13 +02:00
|
|
|
if(!sel || !sel->isfloating || sel->isfixed || !arg)
|
2007-12-27 13:22:40 +01:00
|
|
|
{
|
|
|
|
p_delete(&curtags);
|
2007-10-01 20:42:59 +02:00
|
|
|
return;
|
2007-12-27 13:22:40 +01:00
|
|
|
}
|
|
|
|
p_delete(&curtags);
|
2007-10-01 20:42:59 +02:00
|
|
|
if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
|
|
|
|
return;
|
2008-01-05 20:18:30 +01:00
|
|
|
area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
|
|
|
|
area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
|
|
|
|
area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
|
|
|
|
area.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
|
|
|
|
2007-12-19 04:26:20 +01:00
|
|
|
Bool xqp = XQueryPointer(globalconf.display,
|
|
|
|
RootWindow(globalconf.display,
|
|
|
|
get_phys_screen(screen)),
|
|
|
|
&dummy, &dummy, &mx, &my, &dx, &dy, &dui);
|
2008-01-06 20:43:13 +01:00
|
|
|
client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
|
2007-10-01 20:42:59 +02:00
|
|
|
if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
|
|
|
|
{
|
2008-01-05 19:38:50 +01:00
|
|
|
nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
|
|
|
|
nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
|
2007-12-19 04:26:20 +01:00
|
|
|
XWarpPointer(globalconf.display,
|
|
|
|
None, sel->win,
|
|
|
|
0, 0, 0, 0, nmx, nmy);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-12-27 20:49:38 +01:00
|
|
|
client_kill(Client *c)
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
|
|
|
XEvent ev;
|
|
|
|
|
2008-01-29 08:21:05 +01:00
|
|
|
if(client_isprotodel(globalconf.display, c->win))
|
2007-10-01 20:42:59 +02:00
|
|
|
{
|
|
|
|
ev.type = ClientMessage;
|
2007-12-27 20:49:38 +01:00
|
|
|
ev.xclient.window = c->win;
|
2007-12-16 02:45:38 +01:00
|
|
|
ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
|
2007-10-01 20:42:59 +02:00
|
|
|
ev.xclient.format = 32;
|
2007-12-16 02:45:38 +01:00
|
|
|
ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
|
2007-10-01 20:42:59 +02:00
|
|
|
ev.xclient.data.l[1] = CurrentTime;
|
2007-12-27 20:49:38 +01:00
|
|
|
XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
|
|
|
else
|
2007-12-27 20:49:38 +01:00
|
|
|
XKillClient(globalconf.display, c->win);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Kill selected client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *sel = globalconf.focus->client;
|
|
|
|
|
|
|
|
if(sel)
|
|
|
|
client_kill(sel);
|
2007-10-01 20:42:59 +02:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
|
2008-01-06 14:40:23 +01:00
|
|
|
static void
|
|
|
|
client_maximize(Client *c, Area geometry)
|
2008-01-01 17:37:16 +01:00
|
|
|
{
|
2008-01-06 14:40:23 +01:00
|
|
|
|
2008-01-01 17:37:16 +01:00
|
|
|
if((c->ismax = !c->ismax))
|
|
|
|
{
|
|
|
|
c->wasfloating = c->isfloating;
|
2008-01-06 14:40:23 +01:00
|
|
|
c->m_geometry = c->geometry;
|
2008-01-11 17:54:48 +01:00
|
|
|
if(get_current_layout(c->screen)->arrange != layout_floating)
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
2008-01-06 14:40:23 +01:00
|
|
|
client_resize(c, geometry, False);
|
2008-01-07 18:12:38 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
else if(c->wasfloating)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
2008-01-06 14:40:23 +01:00
|
|
|
client_resize(c, c->m_geometry, False);
|
2008-01-07 18:12:38 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-01-11 16:38:41 +01:00
|
|
|
else if(get_current_layout(c->screen)->arrange == layout_floating)
|
|
|
|
{
|
|
|
|
client_resize(c, c->m_geometry, False);
|
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
else
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, False);
|
2008-01-07 18:12:38 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Toggle maximize for client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *sel = globalconf.focus->client;
|
2008-01-29 19:06:44 +01:00
|
|
|
Area 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
|
|
|
}
|
|
|
|
|
|
|
|
/** Toggle vertical maximize for client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *sel = globalconf.focus->client;
|
2008-01-29 19:06:44 +01:00
|
|
|
Area 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Toggle horizontal maximize for client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *sel = globalconf.focus->client;
|
2008-01-29 19:06:44 +01:00
|
|
|
Area 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
|
|
|
}
|
|
|
|
|
|
|
|
/** Zoom client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
2008-01-07 19:07:22 +01:00
|
|
|
Client *c, *sel = globalconf.focus->client;
|
2008-01-01 17:37:16 +01:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
if(!sel)
|
|
|
|
return;
|
|
|
|
|
2008-01-12 17:01:21 +01:00
|
|
|
client_list_detach(&globalconf.clients, sel);
|
|
|
|
client_list_push(&globalconf.clients, sel);
|
2008-01-17 19:17:53 +01:00
|
|
|
globalconf.screens[screen].need_arrange = True;
|
2008-01-28 16:46:31 +01:00
|
|
|
globalconf.drop_events |= EnterWindowMask;
|
2008-01-01 17:37:16 +01:00
|
|
|
}
|
|
|
|
|
2008-01-17 14:16:45 +01:00
|
|
|
/** Send focus to next client in stack
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *c, *sel = globalconf.focus->client;
|
|
|
|
|
|
|
|
if(!sel)
|
|
|
|
return;
|
|
|
|
for(c = sel->next; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
|
|
|
|
if(!c)
|
|
|
|
for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
|
|
|
|
if(c)
|
2008-01-27 19:07:39 +01:00
|
|
|
client_focus(c, screen, False);
|
2008-01-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Send focus to previous client in stack
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg Unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
Client *prev;
|
|
|
|
|
|
|
|
if((prev = client_find_prev_visible(globalconf.focus->client)))
|
2008-01-27 19:07:39 +01:00
|
|
|
client_focus(prev, screen, False);
|
2008-01-17 14:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Toggle floating state of a client
|
|
|
|
* \param screen Screen ID
|
|
|
|
* \param arg unused
|
|
|
|
* \ingroup ui_callback
|
|
|
|
*/
|
|
|
|
void
|
2008-01-18 10:37:13 +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)
|
|
|
|
client_setfloating(globalconf.focus->client, !globalconf.focus->client->isfloating);
|
2008-01-17 14:16:45 +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
|