2007-10-26 18:23:15 +02:00
|
|
|
/*
|
|
|
|
* window.c - window handling functions
|
|
|
|
*
|
|
|
|
* Copyright © 2007 Julien Danjou <julien@danjou.info>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
2007-10-26 19:35:07 +02:00
|
|
|
#include <X11/extensions/shape.h>
|
2007-10-26 18:23:15 +02:00
|
|
|
|
|
|
|
#include "window.h"
|
2008-01-21 18:14:59 +01:00
|
|
|
#include "common/util.h"
|
2007-10-26 18:23:15 +02:00
|
|
|
|
2007-12-19 04:46:44 +01:00
|
|
|
extern AwesomeConf globalconf;
|
2007-12-16 02:45:38 +01:00
|
|
|
|
2008-01-23 15:18:37 +01:00
|
|
|
/** Mask shorthands, used in event.c and window.c */
|
|
|
|
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
|
|
|
|
|
2007-10-26 18:23:15 +02:00
|
|
|
/** Set client WM_STATE property
|
|
|
|
* \param win Window
|
|
|
|
* \param state state
|
2008-01-12 23:18:10 +01:00
|
|
|
* \return XChangeProperty result
|
2007-10-26 18:23:15 +02:00
|
|
|
*/
|
|
|
|
int
|
2007-12-30 15:24:51 +01:00
|
|
|
window_setstate(Window win, long state)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
|
|
|
long data[] = { state, None };
|
|
|
|
|
2007-12-30 15:24:51 +01:00
|
|
|
return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False),
|
|
|
|
XInternAtom(globalconf.display, "WM_STATE", False), 32,
|
2007-10-26 18:23:15 +02:00
|
|
|
PropModeReplace, (unsigned char *) data, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get a window state (WM_STATE)
|
|
|
|
* \param w Client window
|
|
|
|
* \return state
|
|
|
|
*/
|
|
|
|
long
|
2007-12-30 15:24:51 +01:00
|
|
|
window_getstate(Window w)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
|
|
|
int format;
|
|
|
|
long result = -1;
|
|
|
|
unsigned char *p = NULL;
|
|
|
|
unsigned long n, extra;
|
|
|
|
Atom real;
|
2007-12-30 15:24:51 +01:00
|
|
|
if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False),
|
|
|
|
0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False),
|
2007-10-26 18:23:15 +02:00
|
|
|
&real, &format, &n, &extra, (unsigned char **) &p) != Success)
|
|
|
|
return -1;
|
|
|
|
if(n != 0)
|
|
|
|
result = *p;
|
|
|
|
p_delete(&p);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status
|
2008-01-05 20:25:55 +01:00
|
|
|
window_configure(Window win, Area geometry, int border)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
|
|
|
XConfigureEvent ce;
|
|
|
|
|
|
|
|
ce.type = ConfigureNotify;
|
2007-12-30 15:24:51 +01:00
|
|
|
ce.display = globalconf.display;
|
2007-10-26 18:23:15 +02:00
|
|
|
ce.event = win;
|
|
|
|
ce.window = win;
|
2008-01-05 20:25:55 +01:00
|
|
|
ce.x = geometry.x;
|
|
|
|
ce.y = geometry.y;
|
|
|
|
ce.width = geometry.width;
|
|
|
|
ce.height = geometry.height;
|
2007-10-26 18:23:15 +02:00
|
|
|
ce.border_width = border;
|
|
|
|
ce.above = None;
|
|
|
|
ce.override_redirect = False;
|
2007-12-30 15:24:51 +01:00
|
|
|
return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 19:45:33 +02:00
|
|
|
/** Grab or ungrab buttons on a window
|
2007-12-16 03:14:47 +01:00
|
|
|
* \param screen The screen
|
2007-12-19 04:26:20 +01:00
|
|
|
* \param win The window
|
2007-10-26 19:45:33 +02:00
|
|
|
* \param focused True if client is focused
|
|
|
|
* \param raised True if the client is above other clients
|
|
|
|
*/
|
|
|
|
void
|
2008-01-25 12:55:44 +01:00
|
|
|
window_grabbuttons(int screen, Window win, Bool raised)
|
2007-10-26 19:45:33 +02:00
|
|
|
{
|
2007-11-12 13:21:28 +01:00
|
|
|
Button *b;
|
2007-11-12 10:53:48 +01:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
if(!raised)
|
2007-10-26 19:45:33 +02:00
|
|
|
{
|
2008-01-25 12:55:44 +01:00
|
|
|
XGrabButton(globalconf.display, Button1, NoSymbol,
|
|
|
|
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
|
|
|
XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
|
|
|
|
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
|
|
|
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
|
|
|
|
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
|
|
|
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
|
|
|
|
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
|
|
|
|
}
|
2007-10-26 19:45:33 +02:00
|
|
|
|
2008-01-25 12:55:44 +01:00
|
|
|
for(b = globalconf.buttons.client; b; b = b->next)
|
|
|
|
{
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod,
|
|
|
|
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
|
|
|
|
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
|
|
|
|
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
|
|
|
|
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
2007-10-26 19:45:33 +02:00
|
|
|
}
|
2008-01-25 12:55:44 +01:00
|
|
|
|
|
|
|
XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_root_grabbuttons(int screen)
|
|
|
|
{
|
|
|
|
Button *b;
|
|
|
|
|
|
|
|
for(b = globalconf.buttons.root; b; b = b->next)
|
2007-10-26 19:45:33 +02:00
|
|
|
{
|
2008-01-25 12:55:44 +01:00
|
|
|
XGrabButton(globalconf.display, b->button, b->mod,
|
|
|
|
RootWindow(globalconf.display, screen), False, BUTTONMASK,
|
|
|
|
GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
|
|
|
|
RootWindow(globalconf.display, screen), False, BUTTONMASK,
|
|
|
|
GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
|
|
|
|
RootWindow(globalconf.display, screen), False, BUTTONMASK,
|
|
|
|
GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
|
|
|
|
RootWindow(globalconf.display, screen), False, BUTTONMASK,
|
2007-10-26 19:45:33 +02:00
|
|
|
GrabModeAsync, GrabModeSync, None, None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 19:35:07 +02:00
|
|
|
void
|
2007-12-30 15:24:51 +01:00
|
|
|
window_setshape(int screen, Window win)
|
2007-10-26 19:35:07 +02:00
|
|
|
{
|
|
|
|
int bounding_shaped;
|
|
|
|
int i, b; unsigned int u; /* dummies */
|
|
|
|
/* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
|
2007-12-30 15:24:51 +01:00
|
|
|
if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i,
|
2007-10-26 19:35:07 +02:00
|
|
|
&u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
|
2007-12-30 15:24:51 +01:00
|
|
|
XShapeCombineShape(globalconf.display, RootWindow(globalconf.display, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
|
2007-10-26 19:35:07 +02:00
|
|
|
}
|
|
|
|
|
2008-01-12 23:18:10 +01:00
|
|
|
int
|
2007-12-30 15:24:51 +01:00
|
|
|
window_settrans(Window win, double opacity)
|
2007-10-26 18:23:15 +02:00
|
|
|
{
|
2008-01-12 23:18:10 +01:00
|
|
|
int status;
|
2007-10-26 18:23:15 +02:00
|
|
|
unsigned int real_opacity = 0xffffffff;
|
|
|
|
|
|
|
|
if(opacity >= 0 && opacity <= 100)
|
|
|
|
{
|
|
|
|
real_opacity = ((opacity / 100.0) * 0xffffffff);
|
2008-01-12 23:18:10 +01:00
|
|
|
status = XChangeProperty(globalconf.display, win,
|
|
|
|
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
|
|
|
|
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
else
|
2008-01-12 23:18:10 +01:00
|
|
|
status = XDeleteProperty(globalconf.display, win,
|
|
|
|
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
|
|
|
|
|
|
|
|
return status;
|
2007-10-26 18:23:15 +02:00
|
|
|
}
|
|
|
|
|
2008-01-23 15:54:30 +01:00
|
|
|
SimpleWindow *
|
|
|
|
simplewindow_new(int phys_screen, int x, int y, unsigned int w, unsigned int h,
|
2008-01-24 10:37:16 +01:00
|
|
|
unsigned int border_width)
|
2008-01-23 15:54:30 +01:00
|
|
|
{
|
|
|
|
XSetWindowAttributes wa;
|
|
|
|
SimpleWindow *sw;
|
|
|
|
|
|
|
|
sw = p_new(SimpleWindow, 1);
|
2008-01-23 16:05:52 +01:00
|
|
|
|
|
|
|
sw->geometry.x = x;
|
|
|
|
sw->geometry.y = y;
|
|
|
|
sw->geometry.width = w;
|
|
|
|
sw->geometry.height = h;
|
|
|
|
|
2008-01-23 15:54:30 +01:00
|
|
|
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
|
|
|
|
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
|
|
|
|
wa.cursor = globalconf.cursor[CurNormal];
|
|
|
|
wa.override_redirect = 1;
|
|
|
|
wa.background_pixmap = ParentRelative;
|
|
|
|
wa.event_mask = ButtonPressMask | ExposureMask;
|
|
|
|
sw->window = XCreateWindow(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, phys_screen),
|
|
|
|
x, y, w, h,
|
|
|
|
border_width,
|
|
|
|
DefaultDepth(globalconf.display, phys_screen),
|
|
|
|
CopyFromParent,
|
|
|
|
DefaultVisual(globalconf.display, phys_screen),
|
|
|
|
CWOverrideRedirect | CWBackPixmap | CWEventMask,
|
|
|
|
&wa);
|
|
|
|
|
2008-01-24 10:37:16 +01:00
|
|
|
sw->drawable = XCreatePixmap(globalconf.display,
|
|
|
|
RootWindow(globalconf.display, phys_screen),
|
|
|
|
w, h,
|
|
|
|
DefaultDepth(globalconf.display, phys_screen));
|
2008-01-23 15:54:30 +01:00
|
|
|
|
|
|
|
XDefineCursor(globalconf.display,
|
|
|
|
sw->window,
|
|
|
|
globalconf.cursor[CurNormal]);
|
|
|
|
|
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
simplewindow_delete(SimpleWindow *sw)
|
|
|
|
{
|
|
|
|
XDestroyWindow(globalconf.display, sw->window);
|
|
|
|
XFreePixmap(globalconf.display, sw->drawable);
|
|
|
|
p_delete(&sw);
|
|
|
|
}
|
|
|
|
|
2008-01-23 16:10:05 +01:00
|
|
|
int
|
|
|
|
simplewindow_move(SimpleWindow *sw, int x, int y)
|
|
|
|
{
|
|
|
|
sw->geometry.x = x;
|
|
|
|
sw->geometry.y = y;
|
2008-01-23 16:54:30 +01:00
|
|
|
return XMoveWindow(globalconf.display, sw->window, x, y);
|
2008-01-23 16:10:05 +01:00
|
|
|
}
|
|
|
|
|
2008-01-23 19:51:16 +01:00
|
|
|
int
|
|
|
|
simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen)
|
|
|
|
{
|
|
|
|
return XCopyArea(globalconf.display, sw->drawable,
|
|
|
|
sw->window,
|
|
|
|
DefaultGC(globalconf.display, phys_screen), 0, 0,
|
|
|
|
sw->geometry.width,
|
|
|
|
sw->geometry.height,
|
|
|
|
0, 0);
|
|
|
|
}
|
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|