2007-12-27 17:27:20 +01:00
|
|
|
/*
|
|
|
|
* ewmh.c - EWMH support functions
|
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-12-27 17:27:20 +01: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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-06-18 08:55:31 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_atom.h>
|
2008-03-27 16:05:37 +01:00
|
|
|
#include <xcb/xcb_aux.h>
|
2007-12-27 17:27:20 +01:00
|
|
|
|
|
|
|
#include "ewmh.h"
|
2008-06-09 21:43:09 +02:00
|
|
|
#include "tag.h"
|
2007-12-27 19:33:01 +01:00
|
|
|
#include "focus.h"
|
2007-12-28 18:31:31 +01:00
|
|
|
#include "screen.h"
|
2008-01-01 17:25:48 +01:00
|
|
|
#include "client.h"
|
2008-01-07 18:12:38 +01:00
|
|
|
#include "widget.h"
|
2008-06-17 21:47:57 +02:00
|
|
|
#include "cnode.h"
|
2008-04-24 22:58:25 +02:00
|
|
|
#include "titlebar.h"
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2008-05-24 08:59:27 +02:00
|
|
|
extern awesome_t globalconf;
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_supported;
|
|
|
|
static xcb_atom_t net_client_list;
|
2008-06-17 21:47:57 +02:00
|
|
|
static xcb_atom_t net_client_list_stacking;
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_number_of_desktops;
|
|
|
|
static xcb_atom_t net_current_desktop;
|
|
|
|
static xcb_atom_t net_desktop_names;
|
|
|
|
static xcb_atom_t net_active_window;
|
2008-06-17 22:12:30 +02:00
|
|
|
static xcb_atom_t net_workarea;
|
|
|
|
static xcb_atom_t net_supporting_wm_check;
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_close_window;
|
|
|
|
static xcb_atom_t net_wm_name;
|
2008-06-17 22:48:34 +02:00
|
|
|
static xcb_atom_t net_wm_visible_name;
|
2008-06-18 00:08:04 +02:00
|
|
|
static xcb_atom_t net_wm_desktop;
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_wm_icon_name;
|
2008-06-17 22:49:28 +02:00
|
|
|
static xcb_atom_t net_wm_visible_icon_name;
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_wm_window_type;
|
|
|
|
static xcb_atom_t net_wm_window_type_normal;
|
|
|
|
static xcb_atom_t net_wm_window_type_dock;
|
|
|
|
static xcb_atom_t net_wm_window_type_splash;
|
|
|
|
static xcb_atom_t net_wm_window_type_dialog;
|
|
|
|
static xcb_atom_t net_wm_icon;
|
2008-06-18 08:55:31 +02:00
|
|
|
static xcb_atom_t net_wm_pid;
|
2008-03-21 16:50:17 +01:00
|
|
|
static xcb_atom_t net_wm_state;
|
|
|
|
static xcb_atom_t net_wm_state_sticky;
|
|
|
|
static xcb_atom_t net_wm_state_skip_taskbar;
|
|
|
|
static xcb_atom_t net_wm_state_fullscreen;
|
|
|
|
static xcb_atom_t net_wm_state_above;
|
|
|
|
static xcb_atom_t net_wm_state_below;
|
2008-06-13 14:41:10 +02:00
|
|
|
static xcb_atom_t net_wm_state_modal;
|
2008-06-13 17:33:59 +02:00
|
|
|
static xcb_atom_t net_wm_state_hidden;
|
2008-06-17 22:57:54 +02:00
|
|
|
static xcb_atom_t net_wm_state_demands_attention;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
static xcb_atom_t utf8_string;
|
2007-12-27 19:11:18 +01:00
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *name;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_atom_t *atom;
|
2007-12-27 17:27:20 +01:00
|
|
|
} AtomItem;
|
|
|
|
|
|
|
|
static AtomItem AtomNames[] =
|
|
|
|
{
|
|
|
|
{ "_NET_SUPPORTED", &net_supported },
|
|
|
|
{ "_NET_CLIENT_LIST", &net_client_list },
|
2008-06-17 21:47:57 +02:00
|
|
|
{ "_NET_CLIENT_LIST_STACKING", &net_client_list_stacking },
|
2007-12-27 18:18:12 +01:00
|
|
|
{ "_NET_NUMBER_OF_DESKTOPS", &net_number_of_desktops },
|
2007-12-27 18:42:20 +01:00
|
|
|
{ "_NET_CURRENT_DESKTOP", &net_current_desktop },
|
2007-12-27 19:11:18 +01:00
|
|
|
{ "_NET_DESKTOP_NAMES", &net_desktop_names },
|
2007-12-27 19:33:01 +01:00
|
|
|
{ "_NET_ACTIVE_WINDOW", &net_active_window },
|
2008-06-17 22:12:30 +02:00
|
|
|
{ "_NET_WORKAREA", &net_workarea },
|
|
|
|
{ "_NET_SUPPORTING_WM_CHECK", &net_supporting_wm_check },
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2007-12-27 20:49:38 +01:00
|
|
|
{ "_NET_CLOSE_WINDOW", &net_close_window },
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
{ "_NET_WM_NAME", &net_wm_name },
|
2008-06-17 22:48:34 +02:00
|
|
|
{ "_NET_WM_VISIBLE_NAME", &net_wm_visible_name },
|
2008-06-18 00:08:04 +02:00
|
|
|
{ "_NET_WM_DESKTOP", &net_wm_desktop },
|
2007-12-28 21:58:21 +01:00
|
|
|
{ "_NET_WM_ICON_NAME", &net_wm_icon_name },
|
2008-06-17 22:49:28 +02:00
|
|
|
{ "_NET_WM_VISIBLE_ICON_NAME", &net_wm_visible_icon_name },
|
2007-12-28 20:48:29 +01:00
|
|
|
{ "_NET_WM_WINDOW_TYPE", &net_wm_window_type },
|
|
|
|
{ "_NET_WM_WINDOW_TYPE_NORMAL", &net_wm_window_type_normal },
|
|
|
|
{ "_NET_WM_WINDOW_TYPE_DOCK", &net_wm_window_type_dock },
|
2007-12-28 22:01:22 +01:00
|
|
|
{ "_NET_WM_WINDOW_TYPE_SPLASH", &net_wm_window_type_splash },
|
2008-01-06 22:28:27 +01:00
|
|
|
{ "_NET_WM_WINDOW_TYPE_DIALOG", &net_wm_window_type_dialog },
|
2007-12-27 17:27:20 +01:00
|
|
|
{ "_NET_WM_ICON", &net_wm_icon },
|
2008-06-18 08:55:31 +02:00
|
|
|
{ "_NET_WM_PID", &net_wm_pid },
|
2007-12-27 22:39:29 +01:00
|
|
|
{ "_NET_WM_STATE", &net_wm_state },
|
|
|
|
{ "_NET_WM_STATE_STICKY", &net_wm_state_sticky },
|
2008-01-03 13:15:15 +01:00
|
|
|
{ "_NET_WM_STATE_SKIP_TASKBAR", &net_wm_state_skip_taskbar },
|
2007-12-28 18:31:31 +01:00
|
|
|
{ "_NET_WM_STATE_FULLSCREEN", &net_wm_state_fullscreen },
|
2008-04-08 19:52:59 +02:00
|
|
|
{ "_NET_WM_STATE_ABOVE", &net_wm_state_above },
|
|
|
|
{ "_NET_WM_STATE_BELOW", &net_wm_state_below },
|
2008-06-13 14:41:10 +02:00
|
|
|
{ "_NET_WM_STATE_MODAL", &net_wm_state_modal },
|
2008-06-13 17:33:59 +02:00
|
|
|
{ "_NET_WM_STATE_HIDDEN", &net_wm_state_hidden },
|
2008-06-17 22:57:54 +02:00
|
|
|
{ "_NET_WM_STATE_DEMANDS_ATTENTION", &net_wm_state_demands_attention },
|
2007-12-27 19:11:18 +01:00
|
|
|
|
|
|
|
{ "UTF8_STRING", &utf8_string },
|
2007-12-27 17:27:20 +01:00
|
|
|
};
|
|
|
|
|
2008-02-13 06:53:08 +01:00
|
|
|
#define ATOM_NUMBER (sizeof(AtomNames)/sizeof(AtomItem))
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2007-12-28 18:31:31 +01:00
|
|
|
#define _NET_WM_STATE_REMOVE 0
|
|
|
|
#define _NET_WM_STATE_ADD 1
|
|
|
|
#define _NET_WM_STATE_TOGGLE 2
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
void
|
|
|
|
ewmh_init_atoms(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_intern_atom_cookie_t cs[ATOM_NUMBER];
|
|
|
|
xcb_intern_atom_reply_t *r;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
/*
|
|
|
|
* Create the atom and get the reply in a XCB way (e.g. send all
|
|
|
|
* the requests at the same time and then get the replies)
|
|
|
|
*/
|
2007-12-27 17:27:20 +01:00
|
|
|
for(i = 0; i < ATOM_NUMBER; i++)
|
2008-03-21 16:50:17 +01:00
|
|
|
cs[i] = xcb_intern_atom_unchecked(globalconf.connection,
|
|
|
|
false,
|
|
|
|
strlen(AtomNames[i].name),
|
|
|
|
AtomNames[i].name);
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
for(i = 0; i < ATOM_NUMBER; i++)
|
2008-03-21 16:50:17 +01:00
|
|
|
{
|
2008-04-09 12:56:52 +02:00
|
|
|
if(!(r = xcb_intern_atom_reply(globalconf.connection, cs[i], NULL)))
|
2008-03-21 16:50:17 +01:00
|
|
|
/* An error occured, get reply for next atom */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*AtomNames[i].atom = r->atom;
|
|
|
|
p_delete(&r);
|
|
|
|
}
|
2007-12-27 17:27:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_set_supported_hints(int phys_screen)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_atom_t atom[ATOM_NUMBER];
|
2008-06-17 21:25:23 +02:00
|
|
|
xcb_window_t father;
|
|
|
|
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
|
2007-12-27 17:27:20 +01:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
atom[i++] = net_supported;
|
2008-06-17 21:25:23 +02:00
|
|
|
atom[i++] = net_supporting_wm_check;
|
2007-12-27 17:27:20 +01:00
|
|
|
atom[i++] = net_client_list;
|
2008-06-17 21:47:57 +02:00
|
|
|
atom[i++] = net_client_list_stacking;
|
2007-12-27 18:18:12 +01:00
|
|
|
atom[i++] = net_number_of_desktops;
|
2007-12-27 18:42:20 +01:00
|
|
|
atom[i++] = net_current_desktop;
|
2007-12-27 19:11:18 +01:00
|
|
|
atom[i++] = net_desktop_names;
|
2007-12-27 19:33:01 +01:00
|
|
|
atom[i++] = net_active_window;
|
2008-06-17 22:12:30 +02:00
|
|
|
atom[i++] = net_workarea;
|
2007-12-27 20:49:38 +01:00
|
|
|
|
|
|
|
atom[i++] = net_close_window;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
atom[i++] = net_wm_name;
|
2007-12-28 21:58:21 +01:00
|
|
|
atom[i++] = net_wm_icon_name;
|
2008-06-17 22:49:28 +02:00
|
|
|
atom[i++] = net_wm_visible_icon_name;
|
2008-06-18 00:08:04 +02:00
|
|
|
atom[i++] = net_wm_desktop;
|
2007-12-28 20:48:29 +01:00
|
|
|
atom[i++] = net_wm_window_type;
|
|
|
|
atom[i++] = net_wm_window_type_normal;
|
|
|
|
atom[i++] = net_wm_window_type_dock;
|
2007-12-28 22:01:22 +01:00
|
|
|
atom[i++] = net_wm_window_type_splash;
|
2008-01-06 22:28:27 +01:00
|
|
|
atom[i++] = net_wm_window_type_dialog;
|
2007-12-27 17:27:20 +01:00
|
|
|
atom[i++] = net_wm_icon;
|
2008-06-18 08:55:31 +02:00
|
|
|
atom[i++] = net_wm_pid;
|
2007-12-27 22:39:29 +01:00
|
|
|
atom[i++] = net_wm_state;
|
|
|
|
atom[i++] = net_wm_state_sticky;
|
2008-01-03 13:15:15 +01:00
|
|
|
atom[i++] = net_wm_state_skip_taskbar;
|
2007-12-28 18:31:31 +01:00
|
|
|
atom[i++] = net_wm_state_fullscreen;
|
2008-04-08 19:52:59 +02:00
|
|
|
atom[i++] = net_wm_state_above;
|
|
|
|
atom[i++] = net_wm_state_below;
|
2008-06-13 14:41:10 +02:00
|
|
|
atom[i++] = net_wm_state_modal;
|
2008-06-13 17:33:59 +02:00
|
|
|
atom[i++] = net_wm_state_hidden;
|
2008-06-17 22:57:54 +02:00
|
|
|
atom[i++] = net_wm_state_demands_attention;
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 21:25:23 +02:00
|
|
|
xscreen->root, net_supported, ATOM, 32, i, atom);
|
|
|
|
|
|
|
|
/* create our own window */
|
|
|
|
father = xcb_generate_id(globalconf.connection);
|
|
|
|
xcb_create_window(globalconf.connection, xscreen->root_depth,
|
|
|
|
father, xscreen->root, -1, -1, 1, 1, 0,
|
|
|
|
XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
|
|
|
|
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
xscreen->root, net_supporting_wm_check, WINDOW, 32,
|
2008-06-17 22:12:30 +02:00
|
|
|
1, &father);
|
2008-06-17 21:25:23 +02:00
|
|
|
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
father, net_supporting_wm_check, WINDOW, 32,
|
2008-06-17 22:12:30 +02:00
|
|
|
1, &father);
|
2008-06-17 22:47:31 +02:00
|
|
|
|
2008-06-18 08:55:31 +02:00
|
|
|
/* set the window manager name */
|
2008-06-17 22:47:31 +02:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
father, net_wm_name, utf8_string, 8, 7, "awesome");
|
2008-06-18 08:55:31 +02:00
|
|
|
|
|
|
|
/* set the window manager PID */
|
|
|
|
i = getpid();
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
father, net_wm_pid, CARDINAL, 32, 1, &i);
|
2007-12-27 17:27:20 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 18:01:36 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_client_list(int phys_screen)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_window_t *wins;
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2007-12-27 18:01:36 +01:00
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for(c = globalconf.clients; c; c = c->next)
|
2008-02-25 13:19:39 +01:00
|
|
|
n++;
|
2007-12-27 18:01:36 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
wins = p_new(xcb_window_t, n);
|
2007-12-27 18:01:36 +01:00
|
|
|
|
|
|
|
for(n = 0, c = globalconf.clients; c; c = c->next, n++)
|
2008-03-21 10:53:17 +01:00
|
|
|
if(c->phys_screen == phys_screen)
|
2007-12-27 18:01:36 +01:00
|
|
|
wins[n] = c->win;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 16:55:24 +02:00
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
net_client_list, WINDOW, 32, n, wins);
|
2007-12-27 18:01:36 +01:00
|
|
|
|
|
|
|
p_delete(&wins);
|
|
|
|
}
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2008-06-17 21:47:57 +02:00
|
|
|
/** Set the client list in stacking order, bottom to top.
|
|
|
|
* \param phys_screen The physical screen id.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ewmh_update_net_client_list_stacking(int phys_screen)
|
|
|
|
{
|
|
|
|
xcb_window_t *wins;
|
|
|
|
client_node_t *c;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for(c = globalconf.stack; c; c = c->next)
|
|
|
|
n++;
|
|
|
|
|
|
|
|
wins = p_new(xcb_window_t, n);
|
|
|
|
|
|
|
|
for(n = 0, c = *client_node_list_last(&globalconf.stack); c; c = c->prev, n++)
|
|
|
|
if(c->client->phys_screen == phys_screen)
|
|
|
|
wins[n] = c->client->win;
|
|
|
|
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-06-17 23:00:48 +02:00
|
|
|
net_client_list_stacking, WINDOW, 32, n, wins);
|
2008-06-17 21:47:57 +02:00
|
|
|
|
|
|
|
p_delete(&wins);
|
|
|
|
}
|
|
|
|
|
2007-12-27 18:18:12 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_numbers_of_desktop(int phys_screen)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
uint32_t count = 0;
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t *tag;
|
2007-12-27 18:18:12 +01:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
2007-12-27 18:18:12 +01:00
|
|
|
count++;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 16:55:24 +02:00
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
net_number_of_desktops, CARDINAL, 32, 1, &count);
|
2007-12-27 18:18:12 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 18:42:20 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_current_desktop(int phys_screen)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
uint32_t count = 0;
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t *tag, **curtags = tags_get_current(phys_screen);
|
2007-12-27 18:42:20 +01:00
|
|
|
|
2008-06-09 21:43:09 +02:00
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag != curtags[0]; tag = tag->next)
|
2007-12-27 18:42:20 +01:00
|
|
|
count++;
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 16:55:24 +02:00
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
net_current_desktop, CARDINAL, 32, 1, &count);
|
2008-06-09 21:43:09 +02:00
|
|
|
|
|
|
|
p_delete(&curtags);
|
2007-12-27 18:42:20 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 19:11:18 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_desktop_names(int phys_screen)
|
|
|
|
{
|
|
|
|
char buf[1024], *pos;
|
|
|
|
ssize_t len, curr_size;
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t *tag;
|
2007-12-27 19:11:18 +01:00
|
|
|
|
|
|
|
pos = buf;
|
|
|
|
len = 0;
|
2008-06-09 21:43:09 +02:00
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
2007-12-27 19:11:18 +01:00
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
curr_size = a_strlen(tag->name);
|
|
|
|
a_strcpy(pos, sizeof(buf), tag->name);
|
2007-12-27 19:11:18 +01:00
|
|
|
pos += curr_size + 1;
|
|
|
|
len += curr_size + 1;
|
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 16:55:24 +02:00
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
net_desktop_names, utf8_string, 8, len, buf);
|
2007-12-27 19:33:01 +01:00
|
|
|
}
|
|
|
|
|
2008-06-17 22:12:30 +02:00
|
|
|
/** Update the work area space for each physical screen and each desktop.
|
|
|
|
* \param phys_screen The physical screen id.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ewmh_update_workarea(int phys_screen)
|
|
|
|
{
|
|
|
|
uint32_t *area;
|
|
|
|
tag_t *tag;
|
|
|
|
int count = 0;
|
|
|
|
area_t geom = screen_area_get(phys_screen,
|
|
|
|
globalconf.screens[phys_screen].statusbar,
|
|
|
|
&globalconf.screens[phys_screen].padding);
|
|
|
|
|
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
area = p_new(uint32_t, count * 4);
|
|
|
|
for(tag = globalconf.screens[phys_screen].tags, count = 0; tag; tag = tag->next, count++)
|
|
|
|
{
|
|
|
|
area[4 * count + 0] = geom.x;
|
|
|
|
area[4 * count + 1] = geom.y;
|
|
|
|
area[4 * count + 2] = geom.width;
|
|
|
|
area[4 * count + 3] = geom.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
|
|
|
net_workarea, CARDINAL, 32, count, area);
|
|
|
|
p_delete(&area);
|
|
|
|
}
|
|
|
|
|
2007-12-27 19:33:01 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_active_window(int phys_screen)
|
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_window_t win;
|
2008-06-09 21:43:09 +02:00
|
|
|
client_t *sel = focus_get_current_client(phys_screen);
|
2007-12-27 19:33:01 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
win = sel ? sel->win : XCB_NONE;
|
2007-12-27 19:33:01 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE,
|
2008-06-17 16:55:24 +02:00
|
|
|
xutil_screen_get(globalconf.connection, phys_screen)->root,
|
2008-03-21 16:50:17 +01:00
|
|
|
net_active_window, WINDOW, 32, 1, &win);
|
2007-12-27 19:11:18 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 22:39:29 +01:00
|
|
|
static void
|
2008-04-11 11:35:11 +02:00
|
|
|
ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
const uint32_t raise_window_val = XCB_STACK_MODE_ABOVE;
|
|
|
|
|
2007-12-27 22:39:29 +01:00
|
|
|
if(state == net_wm_state_sticky)
|
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_t *tag;
|
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
|
|
|
tag_client(c, tag);
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
2008-01-03 13:15:15 +01:00
|
|
|
else if(state == net_wm_state_skip_taskbar)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
2008-01-17 18:35:14 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
c->skiptb = false;
|
|
|
|
c->skip = false;
|
2008-01-17 18:35:14 +01:00
|
|
|
}
|
2008-01-03 13:15:15 +01:00
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
2008-01-17 18:35:14 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
c->skiptb = true;
|
|
|
|
c->skip = true;
|
2008-01-17 18:35:14 +01:00
|
|
|
}
|
2008-01-03 13:15:15 +01:00
|
|
|
}
|
2007-12-28 18:31:31 +01:00
|
|
|
else if(state == net_wm_state_fullscreen)
|
|
|
|
{
|
2008-03-14 09:37:25 +01:00
|
|
|
area_t geometry = c->geometry;
|
2007-12-28 18:31:31 +01:00
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
2008-01-06 14:40:23 +01:00
|
|
|
{
|
|
|
|
/* restore geometry */
|
|
|
|
geometry = c->m_geometry;
|
2008-03-24 14:44:11 +01:00
|
|
|
/* restore borders and titlebar */
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar && c->titlebar->sw && (c->titlebar->position = c->titlebar->oldposition))
|
|
|
|
xcb_map_window(globalconf.connection, c->titlebar->sw->window);
|
2008-05-28 14:33:45 +02:00
|
|
|
c->noborder = false;
|
2008-05-25 17:42:20 +02:00
|
|
|
c->ismax = false;
|
2008-05-28 14:33:45 +02:00
|
|
|
client_setborder(c, c->oldborder);
|
2008-04-08 19:52:59 +02:00
|
|
|
client_setfloating(c, c->wasfloating, c->oldlayer);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
2008-06-09 21:43:09 +02:00
|
|
|
geometry = screen_area_get(c->screen, NULL, &globalconf.screens[c->screen].padding);
|
2008-01-06 14:40:23 +01:00
|
|
|
/* save geometry */
|
|
|
|
c->m_geometry = c->geometry;
|
|
|
|
c->wasfloating = c->isfloating;
|
2008-03-24 14:44:11 +01:00
|
|
|
/* disable titlebar and borders */
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar && c->titlebar->sw && (c->titlebar->oldposition = c->titlebar->position))
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-04 11:50:21 +02:00
|
|
|
xcb_unmap_window(globalconf.connection, c->titlebar->sw->window);
|
|
|
|
c->titlebar->position = Off;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-05-25 17:42:20 +02:00
|
|
|
c->ismax = true;
|
2008-05-28 14:33:45 +02:00
|
|
|
c->oldborder = c->border;
|
|
|
|
client_setborder(c, 0);
|
|
|
|
c->noborder = true;
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, LAYER_FULLSCREEN);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-06-09 21:43:09 +02:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-03-21 16:50:17 +01:00
|
|
|
client_resize(c, geometry, false);
|
|
|
|
xcb_configure_window(globalconf.connection, c->win, XCB_CONFIG_WINDOW_STACK_MODE, &raise_window_val);
|
2007-12-28 18:31:31 +01:00
|
|
|
}
|
2008-04-08 19:52:59 +02:00
|
|
|
else if(state == net_wm_state_above)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
|
|
|
c->layer = c->oldlayer;
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
|
|
|
c->oldlayer = c->layer;
|
|
|
|
c->layer = LAYER_ABOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(state == net_wm_state_below)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
|
|
|
c->layer = c->oldlayer;
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
|
|
|
c->oldlayer = c->layer;
|
|
|
|
c->layer = LAYER_BELOW;
|
|
|
|
}
|
|
|
|
}
|
2008-06-13 14:41:10 +02:00
|
|
|
else if(state == net_wm_state_modal)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
|
|
|
c->layer = c->oldlayer;
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
|
|
|
c->oldlayer = c->layer;
|
|
|
|
c->layer = LAYER_MODAL;
|
|
|
|
}
|
|
|
|
}
|
2008-06-13 17:33:59 +02:00
|
|
|
else if(state == net_wm_state_hidden)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
|
|
|
c->ishidden = false;
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
c->ishidden = true;
|
|
|
|
globalconf.screens[c->screen].need_arrange = true;
|
|
|
|
}
|
2008-06-17 22:57:54 +02:00
|
|
|
else if(state == net_wm_state_demands_attention)
|
|
|
|
{
|
|
|
|
if(set == _NET_WM_STATE_REMOVE)
|
|
|
|
c->isurgent = false;
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
|
|
|
c->isurgent = true;
|
|
|
|
/* execute hook */
|
|
|
|
luaA_client_userdata_new(c);
|
|
|
|
luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1);
|
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
|
|
|
}
|
|
|
|
}
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
static void
|
2008-04-11 11:35:11 +02:00
|
|
|
ewmh_process_window_type_atom(client_t *c, xcb_atom_t state)
|
2007-12-28 20:48:29 +01:00
|
|
|
{
|
|
|
|
if(state == net_wm_window_type_normal)
|
|
|
|
{
|
2008-01-06 22:28:27 +01:00
|
|
|
/* do nothing. this is REALLY IMPORTANT */
|
2007-12-28 20:48:29 +01:00
|
|
|
}
|
2007-12-28 22:01:22 +01:00
|
|
|
else if(state == net_wm_window_type_dock
|
|
|
|
|| state == net_wm_window_type_splash)
|
2007-12-28 20:48:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
c->skip = true;
|
|
|
|
c->isfixed = true;
|
2008-06-04 11:50:21 +02:00
|
|
|
if(c->titlebar && c->titlebar->position && c->titlebar->sw)
|
2008-05-20 15:39:47 +02:00
|
|
|
{
|
2008-06-04 11:50:21 +02:00
|
|
|
xcb_unmap_window(globalconf.connection, c->titlebar->sw->window);
|
|
|
|
c->titlebar->position = Off;
|
2008-05-20 15:39:47 +02:00
|
|
|
}
|
2008-05-28 14:33:45 +02:00
|
|
|
client_setborder(c, 0);
|
|
|
|
c->noborder = true;
|
2008-03-21 16:50:17 +01:00
|
|
|
client_setfloating(c, true, LAYER_ABOVE);
|
2007-12-28 20:48:29 +01:00
|
|
|
}
|
2008-01-06 22:28:27 +01:00
|
|
|
else if (state == net_wm_window_type_dialog)
|
2008-06-13 14:41:10 +02:00
|
|
|
client_setfloating(c, true, LAYER_MODAL);
|
2007-12-28 20:48:29 +01:00
|
|
|
}
|
2008-04-08 19:52:59 +02:00
|
|
|
|
2008-06-14 18:12:16 +02:00
|
|
|
int
|
2008-03-21 16:50:17 +01:00
|
|
|
ewmh_process_client_message(xcb_client_message_event_t *ev)
|
2007-12-27 20:49:38 +01:00
|
|
|
{
|
2008-04-11 11:35:11 +02:00
|
|
|
client_t *c;
|
2008-06-18 00:08:04 +02:00
|
|
|
tag_t *tag;
|
2007-12-28 22:16:27 +01:00
|
|
|
int screen;
|
2008-06-18 00:08:04 +02:00
|
|
|
unsigned int i;
|
2007-12-28 22:16:27 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
if(ev->type == net_current_desktop)
|
|
|
|
for(screen = 0;
|
|
|
|
screen < xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
|
|
|
|
screen++)
|
2008-06-09 21:43:09 +02:00
|
|
|
{
|
2008-06-17 16:55:24 +02:00
|
|
|
if(ev->window == xutil_screen_get(globalconf.connection, screen)->root)
|
2008-06-09 21:43:09 +02:00
|
|
|
tag_view_only_byindex(screen, ev->data.data32[0]);
|
|
|
|
}
|
2008-06-17 22:14:14 +02:00
|
|
|
else if(ev->type == net_close_window)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-06-05 09:25:38 +02:00
|
|
|
if((c = client_getbywin(ev->window)))
|
2007-12-27 20:49:38 +01:00
|
|
|
client_kill(c);
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
2008-06-18 00:08:04 +02:00
|
|
|
else if(ev->type == net_wm_desktop)
|
|
|
|
{
|
|
|
|
if((c = client_getbywin(ev->window)))
|
|
|
|
{
|
|
|
|
if(ev->data.data32[0] == 0xffffffff)
|
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
|
|
|
tag_client(c, tag);
|
|
|
|
else
|
|
|
|
for(i = 0, tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
|
|
|
|
if(ev->data.data32[0] == i)
|
|
|
|
tag_client(c, tag);
|
|
|
|
else
|
|
|
|
untag_client(c, tag);
|
|
|
|
}
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
else if(ev->type == net_wm_state)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-06-05 09:25:38 +02:00
|
|
|
if((c = client_getbywin(ev->window)))
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[1], ev->data.data32[0]);
|
|
|
|
if(ev->data.data32[2])
|
|
|
|
ewmh_process_state_atom(c, (xcb_atom_t) ev->data.data32[2],
|
|
|
|
ev->data.data32[0]);
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
}
|
2008-06-14 18:12:16 +02:00
|
|
|
|
|
|
|
return 0;
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-04-11 11:35:11 +02:00
|
|
|
ewmh_check_client_hints(client_t *c)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_atom_t *state;
|
|
|
|
void *data = NULL;
|
2008-06-18 00:08:04 +02:00
|
|
|
int i, desktop;
|
|
|
|
xcb_get_property_cookie_t c0, c1, c2;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_get_property_reply_t *reply;
|
2008-06-18 00:08:04 +02:00
|
|
|
tag_t *tag;
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
/* Send the GetProperty requests which will be processed later */
|
2008-06-18 00:08:04 +02:00
|
|
|
c0 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
net_wm_desktop, XCB_GET_PROPERTY_TYPE_ANY, 0, 1);
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
c1 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
net_wm_state, ATOM, 0, UINT32_MAX);
|
|
|
|
|
|
|
|
c2 = xcb_get_property_unchecked(globalconf.connection, false, c->win,
|
|
|
|
net_wm_window_type, ATOM, 0, UINT32_MAX);
|
|
|
|
|
2008-06-18 00:08:04 +02:00
|
|
|
reply = xcb_get_property_reply(globalconf.connection, c0, NULL);
|
|
|
|
if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
|
|
|
|
{
|
|
|
|
desktop = *(uint32_t *) data;
|
|
|
|
if(desktop == -1)
|
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
|
|
|
tag_client(c, tag);
|
|
|
|
else
|
|
|
|
for(i = 0, tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
|
|
|
|
if(desktop == i)
|
|
|
|
tag_client(c, tag);
|
|
|
|
else
|
|
|
|
untag_client(c, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_delete(&reply);
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
reply = xcb_get_property_reply(globalconf.connection, c1, NULL);
|
|
|
|
if(reply && (data = xcb_get_property_value(reply)))
|
2007-12-28 20:48:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
state = (xcb_atom_t *) data;
|
|
|
|
for(i = 0; i < xcb_get_property_value_length(reply); i++)
|
2007-12-28 20:48:29 +01:00
|
|
|
ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD);
|
|
|
|
}
|
2007-12-27 22:39:29 +01:00
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
p_delete(&reply);
|
|
|
|
|
|
|
|
reply = xcb_get_property_reply(globalconf.connection, c2, NULL);
|
|
|
|
if(reply && (data = xcb_get_property_value(reply)))
|
2007-12-28 20:48:29 +01:00
|
|
|
{
|
2008-03-21 16:50:17 +01:00
|
|
|
state = (xcb_atom_t *) data;
|
|
|
|
for(i = 0; i < xcb_get_property_value_length(reply); i++)
|
2007-12-28 20:48:29 +01:00
|
|
|
ewmh_process_window_type_atom(c, state[i]);
|
|
|
|
}
|
2008-03-21 16:50:17 +01:00
|
|
|
|
|
|
|
p_delete(&reply);
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2008-06-18 09:29:57 +02:00
|
|
|
netwm_icon_t *
|
2008-03-21 16:50:17 +01:00
|
|
|
ewmh_get_window_icon(xcb_window_t w)
|
2008-01-03 19:02:23 +01:00
|
|
|
{
|
2008-03-26 10:26:08 +01:00
|
|
|
double alpha;
|
2008-06-18 09:29:57 +02:00
|
|
|
netwm_icon_t *icon;
|
2008-03-21 16:50:17 +01:00
|
|
|
int size, i;
|
2008-03-27 12:08:31 +01:00
|
|
|
uint32_t *data;
|
2008-03-27 12:34:19 +01:00
|
|
|
unsigned char *imgdata;
|
2008-03-21 16:50:17 +01:00
|
|
|
xcb_get_property_reply_t *r;
|
|
|
|
|
|
|
|
r = xcb_get_property_reply(globalconf.connection,
|
|
|
|
xcb_get_property_unchecked(globalconf.connection, false, w,
|
|
|
|
net_wm_icon, CARDINAL, 0, UINT32_MAX),
|
|
|
|
NULL);
|
2008-04-09 12:56:52 +02:00
|
|
|
if(!r || r->type != CARDINAL || r->format != 32 || r->length < 2 ||
|
2008-03-27 12:34:19 +01:00
|
|
|
!(data = (uint32_t *) xcb_get_property_value(r)))
|
2008-03-21 16:50:17 +01:00
|
|
|
{
|
2008-05-02 10:31:51 +02:00
|
|
|
p_delete(&r);
|
2008-01-03 19:02:23 +01:00
|
|
|
return NULL;
|
2008-03-21 16:50:17 +01:00
|
|
|
}
|
2008-01-03 19:02:23 +01:00
|
|
|
|
2008-06-18 09:29:57 +02:00
|
|
|
icon = p_new(netwm_icon_t, 1);
|
2008-01-03 19:02:23 +01:00
|
|
|
|
|
|
|
icon->width = data[0];
|
|
|
|
icon->height = data[1];
|
|
|
|
size = icon->width * icon->height;
|
|
|
|
|
|
|
|
if(!size)
|
|
|
|
{
|
|
|
|
p_delete(&icon);
|
2008-03-21 16:50:17 +01:00
|
|
|
p_delete(&r);
|
2008-01-03 19:02:23 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon->image = p_new(unsigned char, size * 4);
|
|
|
|
for(imgdata = icon->image, i = 2; i < size + 2; i++, imgdata += 4)
|
|
|
|
{
|
2008-03-26 10:26:08 +01:00
|
|
|
imgdata[3] = (data[i] >> 24) & 0xff; /* A */
|
|
|
|
alpha = imgdata[3] / 255.0;
|
|
|
|
imgdata[2] = ((data[i] >> 16) & 0xff) * alpha; /* R */
|
|
|
|
imgdata[1] = ((data[i] >> 8) & 0xff) * alpha; /* G */
|
|
|
|
imgdata[0] = (data[i] & 0xff) * alpha; /* B */
|
2008-01-03 19:02:23 +01:00
|
|
|
}
|
|
|
|
|
2008-03-21 16:50:17 +01:00
|
|
|
p_delete(&r);
|
2008-01-03 19:02:23 +01:00
|
|
|
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|