...
 
Commits (4)
......@@ -142,9 +142,9 @@ client_create(Window win, bool viewable)
c->dirty = false;
c->border.width = config_get()->window.border.width;
XSetWindowBorderWidth(x11.dpy, c->win, c->border.width);
client_update_size_hints(c);
client_query_size_hints(c);
c->name[0] = '\0';
client_update_name(c);
client_query_name(c);
/* input and appearance */
c->focused = false;
......@@ -193,82 +193,7 @@ client_moveresize(struct client *c, struct position pos, struct size size)
}
void
client_resize(struct client *c, struct size size)
{
/* TODO: add asserts */
size.width = MAX(size.width, 1);
size.height = MAX(size.height, 1);
if (client_check_size_hints(c, &size.width, &size.height)) {
c->dim.size = size;
if (c->floating && !c->fullscreen)
c->dim_floating.size = size;
XResizeWindow(x11.dpy, c->win, size.width, size.height);
}
}
bool
client_send_event(struct client *c, Atom atom)
{
int n;
Atom *supported;
bool exists;
XEvent ev;
if (XGetWMProtocols(x11.dpy, c->win, &supported, &n)) {
while (!exists && n--) {
exists = supported[n] == atom;
}
XFree(supported);
}
if (!exists) {
return false;
}
ev.type = ClientMessage;
ev.xclient.window = c->win;
ev.xclient.message_type = x11.wmatom[WMProtocols];
ev.xclient.format = 32;
ev.xclient.data.l[0] = (int long signed) atom;
ev.xclient.data.l[1] = (int long signed) CurrentTime;
XSendEvent(x11.dpy, c->win, false, NoEventMask, &ev);
return true;
}
void
client_set_focus(struct client *c, bool focus)
{
if (focus == c->focused)
return;
c->focused = focus;
grab_input(c);
set_border(c);
}
void
client_show(struct client *c, bool show)
{
int x, y;
if (show) {
/* FIXME: Currently, "hiding" a window simply means moving it
* off-screen. As such, "showing" a window simply consists of
* moving it back to its place. Since "its place" depends on
* where the workspace that contains it is currently located,
* there is no way for us to know here where we can move a
* window, so we just rely on the workspace/layout moving and
* resizing this client to the right place and shape.
*/
return;
} else {
x = -((int signed) (c->dim.width + 2 * c->border.width));
y = 0;
XMoveWindow(x11.dpy, c->win, x, y);
}
}
void
client_update_name(struct client *c)
client_query_name(struct client *c)
{
XTextProperty xtp;
int n;
......@@ -299,7 +224,7 @@ client_update_name(struct client *c)
}
void
client_update_size_hints(struct client *c)
client_query_size_hints(struct client *c)
{
long size;
XSizeHints hints;
......@@ -347,3 +272,78 @@ client_update_size_hints(struct client *c)
c->maxw = c->maxh = 0;
}
}
void
client_resize(struct client *c, struct size size)
{
/* TODO: add asserts */
size.width = MAX(size.width, 1);
size.height = MAX(size.height, 1);
if (client_check_size_hints(c, &size.width, &size.height)) {
c->dim.size = size;
if (c->floating && !c->fullscreen)
c->dim_floating.size = size;
XResizeWindow(x11.dpy, c->win, size.width, size.height);
}
}
bool
client_send_event(struct client *c, Atom atom)
{
int n;
Atom *supported;
bool exists;
XEvent ev;
if (XGetWMProtocols(x11.dpy, c->win, &supported, &n)) {
while (!exists && n--) {
exists = supported[n] == atom;
}
XFree(supported);
}
if (!exists) {
return false;
}
ev.type = ClientMessage;
ev.xclient.window = c->win;
ev.xclient.message_type = x11.wmatom[WMProtocols];
ev.xclient.format = 32;
ev.xclient.data.l[0] = (int long signed) atom;
ev.xclient.data.l[1] = (int long signed) CurrentTime;
XSendEvent(x11.dpy, c->win, false, NoEventMask, &ev);
return true;
}
void
client_set_focus(struct client *c, bool focus)
{
if (focus == c->focused)
return;
c->focused = focus;
grab_input(c);
set_border(c);
}
void
client_show(struct client *c, bool show)
{
int x, y;
if (show) {
/* FIXME: Currently, "hiding" a window simply means moving it
* off-screen. As such, "showing" a window simply consists of
* moving it back to its place. Since "its place" depends on
* where the workspace that contains it is currently located,
* there is no way for us to know here where we can move a
* window, so we just rely on the workspace/layout moving and
* resizing this client to the right place and shape.
*/
return;
} else {
x = -((int signed) (c->dim.width + 2 * c->border.width));
y = 0;
XMoveWindow(x11.dpy, c->win, x, y);
}
}
......@@ -28,11 +28,11 @@ void client_destroy(struct client *c);
void client_kill(struct client *c);
void client_move(struct client *c, struct position pos);
void client_moveresize(struct client *c, struct position pos, struct size size);
void client_query_name(struct client *c);
void client_query_size_hints(struct client *c);
void client_resize(struct client *c, struct size size);
bool client_send_event(struct client *c, Atom atom);
void client_set_focus(struct client *c, bool focus);
void client_show(struct client *c, bool show);
void client_update_name(struct client *c);
void client_update_size_hints(struct client *c);
#endif /* ndef _KWM_CLIENT_H */
......@@ -713,14 +713,15 @@ propertynotify(XEvent *e)
updatetransient(c);
break;
case XA_WM_NORMAL_HINTS:
client_update_size_hints(c);
client_query_size_hints(c);
/* TODO: apply size hints */
break;
case XA_WM_HINTS:
/* TODO urgent hint */
/* TODO: urgent hint */
break;
}
if (ev->atom == XA_WM_NAME || ev->atom == x11.netatom[NetWMName]) {
client_update_name(c);
client_query_name(c);
}
if (ev->atom == x11.netatom[NetWMWindowType]) {
updateclient(c);
......@@ -976,13 +977,8 @@ setfloating(struct client *c, bool floating)
workspace_set_floating(c->ws, c, floating);
if (c->ws->mon) {
/* TODO: let global restacking function handle this */
if (floating)
XRaiseWindow(x11.dpy, c->win);
else
XLowerWindow(x11.dpy, c->win);
monitor_restack(c->ws->mon);
monitor_arrange(c->ws->mon);
updatefocus();
}
}
......
......@@ -147,6 +147,15 @@ workspace_isempty(struct workspace *ws)
return ws->tiled->size == 0 && ws->floating->size == 0;
}
void
workspace_raise_floating(struct workspace *ws, struct client *c)
{
if (!c->floating)
die("Attempt to raise non-floating client");
list_push(ws->floating, c);
}
void
workspace_rename(struct workspace *ws, char const *name)
{
......
......@@ -28,6 +28,7 @@ void workspace_detach_client(struct workspace *ws, struct client *c);
void workspace_focus(struct workspace *ws, bool focus);
void workspace_focus_client(struct workspace *ws, struct client *c);
bool workspace_isempty(struct workspace *ws);
void workspace_raise_floating(struct workspace *ws, struct client *c);
void workspace_rename(struct workspace *ws, char const *name);
void workspace_set_floating(struct workspace *ws, struct client *c,
bool floating);
......