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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-27 18:18:12 +01:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/Xmd.h>
|
2007-12-27 17:27:20 +01:00
|
|
|
|
|
|
|
#include "ewmh.h"
|
2007-12-27 18:42:20 +01: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"
|
2007-12-27 17:27:20 +01:00
|
|
|
|
|
|
|
extern AwesomeConf globalconf;
|
|
|
|
|
|
|
|
static Atom net_supported;
|
|
|
|
static Atom net_client_list;
|
2007-12-27 18:18:12 +01:00
|
|
|
static Atom net_number_of_desktops;
|
2007-12-27 18:42:20 +01:00
|
|
|
static Atom net_current_desktop;
|
2007-12-27 19:11:18 +01:00
|
|
|
static Atom net_desktop_names;
|
2007-12-27 19:33:01 +01:00
|
|
|
static Atom net_active_window;
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2007-12-27 20:49:38 +01:00
|
|
|
static Atom net_close_window;
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
static Atom net_wm_name;
|
2007-12-28 21:58:21 +01:00
|
|
|
static Atom net_wm_icon_name;
|
2007-12-28 20:48:29 +01:00
|
|
|
static Atom net_wm_window_type;
|
|
|
|
static Atom net_wm_window_type_normal;
|
|
|
|
static Atom net_wm_window_type_dock;
|
2007-12-28 22:01:22 +01:00
|
|
|
static Atom net_wm_window_type_splash;
|
2008-01-06 22:28:27 +01:00
|
|
|
static Atom net_wm_window_type_dialog;
|
2007-12-27 17:27:20 +01:00
|
|
|
static Atom net_wm_icon;
|
2007-12-27 22:39:29 +01:00
|
|
|
static Atom net_wm_state;
|
|
|
|
static Atom net_wm_state_sticky;
|
2008-01-03 13:15:15 +01:00
|
|
|
static Atom net_wm_state_skip_taskbar;
|
2007-12-28 18:31:31 +01:00
|
|
|
static Atom net_wm_state_fullscreen;
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2007-12-27 19:11:18 +01:00
|
|
|
static Atom utf8_string;
|
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
Atom *atom;
|
|
|
|
} AtomItem;
|
|
|
|
|
|
|
|
static AtomItem AtomNames[] =
|
|
|
|
{
|
|
|
|
{ "_NET_SUPPORTED", &net_supported },
|
|
|
|
{ "_NET_CLIENT_LIST", &net_client_list },
|
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 },
|
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 },
|
2007-12-28 21:58:21 +01:00
|
|
|
{ "_NET_WM_ICON_NAME", &net_wm_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 },
|
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 },
|
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;
|
|
|
|
char *names[ATOM_NUMBER];
|
|
|
|
Atom atoms[ATOM_NUMBER];
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2007-12-27 17:27:20 +01:00
|
|
|
for(i = 0; i < ATOM_NUMBER; i++)
|
|
|
|
names[i] = (char *) AtomNames[i].name;
|
|
|
|
XInternAtoms(globalconf.display, names, ATOM_NUMBER, False, atoms);
|
|
|
|
for(i = 0; i < ATOM_NUMBER; i++)
|
|
|
|
*AtomNames[i].atom = atoms[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_set_supported_hints(int phys_screen)
|
|
|
|
{
|
|
|
|
Atom atom[ATOM_NUMBER];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
atom[i++] = net_supported;
|
|
|
|
atom[i++] = net_client_list;
|
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;
|
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;
|
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;
|
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;
|
2007-12-27 17:27:20 +01:00
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
|
|
|
net_supported, XA_ATOM, 32,
|
|
|
|
PropModeReplace, (unsigned char *) atom, i);
|
|
|
|
}
|
|
|
|
|
2007-12-27 18:01:36 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_client_list(int phys_screen)
|
|
|
|
{
|
|
|
|
Window *wins;
|
|
|
|
Client *c;
|
|
|
|
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-02-25 13:19:39 +01:00
|
|
|
wins = p_new(Window, 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;
|
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
|
|
|
net_client_list, XA_WINDOW, 32, PropModeReplace, (unsigned char *) wins, n);
|
|
|
|
|
|
|
|
p_delete(&wins);
|
|
|
|
}
|
2007-12-27 17:27:20 +01:00
|
|
|
|
2007-12-27 18:18:12 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_numbers_of_desktop(int phys_screen)
|
|
|
|
{
|
|
|
|
CARD32 count = 0;
|
|
|
|
Tag *tag;
|
|
|
|
|
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
|
|
|
net_number_of_desktops, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1);
|
|
|
|
}
|
|
|
|
|
2007-12-27 18:42:20 +01:00
|
|
|
void
|
|
|
|
ewmh_update_net_current_desktop(int phys_screen)
|
|
|
|
{
|
|
|
|
CARD32 count = 0;
|
2008-01-29 08:31:13 +01:00
|
|
|
Tag *tag, **curtags = tags_get_current(phys_screen);
|
2007-12-27 18:42:20 +01:00
|
|
|
|
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag != curtags[0]; tag = tag->next)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
|
|
|
net_current_desktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &count, 1);
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2007-12-27 18:42:20 +01:00
|
|
|
p_delete(&curtags);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
Tag *tag;
|
|
|
|
|
|
|
|
pos = buf;
|
|
|
|
len = 0;
|
|
|
|
for(tag = globalconf.screens[phys_screen].tags; tag; tag = tag->next)
|
|
|
|
{
|
|
|
|
curr_size = a_strlen(tag->name);
|
|
|
|
a_strcpy(pos, sizeof(buf), tag->name);
|
|
|
|
pos += curr_size + 1;
|
|
|
|
len += curr_size + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
2007-12-27 19:33:01 +01:00
|
|
|
net_desktop_names, utf8_string, 8, PropModeReplace, (unsigned char *) buf, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_update_net_active_window(int phys_screen)
|
|
|
|
{
|
|
|
|
Window win;
|
2007-12-27 19:57:46 +01:00
|
|
|
Client *sel = focus_get_current_client(phys_screen);
|
2007-12-27 19:33:01 +01:00
|
|
|
|
|
|
|
win = sel ? sel->win : None;
|
|
|
|
|
|
|
|
XChangeProperty(globalconf.display, RootWindow(globalconf.display, phys_screen),
|
|
|
|
net_active_window, XA_WINDOW, 32, PropModeReplace, (unsigned char *) &win, 1);
|
2007-12-27 19:11:18 +01:00
|
|
|
}
|
|
|
|
|
2007-12-27 22:39:29 +01:00
|
|
|
static void
|
2007-12-28 18:31:31 +01:00
|
|
|
ewmh_process_state_atom(Client *c, Atom state, int set)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
|
|
|
if(state == net_wm_state_sticky)
|
|
|
|
{
|
|
|
|
Tag *tag;
|
|
|
|
for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
|
2007-12-27 22:43:59 +01:00
|
|
|
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-01-03 13:15:15 +01:00
|
|
|
c->skiptb = False;
|
2008-02-12 10:06:19 +01:00
|
|
|
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-01-03 13:15:15 +01:00
|
|
|
c->skiptb = True;
|
2008-02-12 10:06:19 +01:00
|
|
|
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;
|
|
|
|
c->border = c->oldborder;
|
2007-12-28 18:31:31 +01:00
|
|
|
c->ismax = False;
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, c->wasfloating);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
|
|
|
else if(set == _NET_WM_STATE_ADD)
|
|
|
|
{
|
2008-01-29 19:06:44 +01:00
|
|
|
geometry = screen_get_area(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;
|
|
|
|
c->oldborder = c->border;
|
|
|
|
c->border = 0;
|
|
|
|
c->ismax = True;
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
2008-01-06 14:40:23 +01:00
|
|
|
}
|
2008-01-07 18:12:38 +01:00
|
|
|
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
|
2008-03-16 10:01:55 +01:00
|
|
|
client_resize(c, geometry, False);
|
2008-01-06 14:40:23 +01:00
|
|
|
XRaiseWindow(globalconf.display, c->win);
|
2007-12-28 18:31:31 +01:00
|
|
|
}
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
static void
|
|
|
|
ewmh_process_window_type_atom(Client *c, Atom state)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
c->border = 0;
|
|
|
|
c->skip = True;
|
|
|
|
c->isfixed = True;
|
2008-03-14 17:38:52 +01:00
|
|
|
c->titlebar.position = Off;
|
2008-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
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-01-17 10:40:39 +01:00
|
|
|
client_setfloating(c, True);
|
2007-12-28 20:48:29 +01:00
|
|
|
}
|
2007-12-27 20:49:38 +01:00
|
|
|
void
|
|
|
|
ewmh_process_client_message(XClientMessageEvent *ev)
|
|
|
|
{
|
|
|
|
Client *c;
|
2007-12-28 22:16:27 +01:00
|
|
|
int screen;
|
|
|
|
|
|
|
|
if(ev->message_type == net_current_desktop)
|
|
|
|
for(screen = 0; screen < ScreenCount(globalconf.display); screen++)
|
|
|
|
if(ev->window == RootWindow(globalconf.display, screen))
|
2008-01-13 15:26:19 +01:00
|
|
|
tag_view_only_byindex(screen, ev->data.l[0]);
|
2007-12-27 20:49:38 +01:00
|
|
|
|
|
|
|
if(ev->message_type == net_close_window)
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
2007-12-27 20:49:38 +01:00
|
|
|
client_kill(c);
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
else if(ev->message_type == net_wm_state)
|
|
|
|
{
|
2008-01-29 08:21:05 +01:00
|
|
|
if((c = client_get_bywin(globalconf.clients, ev->window)))
|
2007-12-27 22:39:29 +01:00
|
|
|
{
|
2007-12-28 18:31:31 +01:00
|
|
|
ewmh_process_state_atom(c, (Atom) ev->data.l[1], ev->data.l[0]);
|
2007-12-27 22:39:29 +01:00
|
|
|
if(ev->data.l[2])
|
2007-12-28 18:31:31 +01:00
|
|
|
ewmh_process_state_atom(c, (Atom) ev->data.l[2], ev->data.l[0]);
|
2007-12-27 22:39:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ewmh_check_client_hints(Client *c)
|
|
|
|
{
|
|
|
|
int format;
|
|
|
|
Atom real, *state;
|
|
|
|
unsigned char *data = NULL;
|
|
|
|
unsigned long i, n, extra;
|
|
|
|
|
|
|
|
if(XGetWindowProperty(globalconf.display, c->win, net_wm_state, 0L, LONG_MAX, False,
|
|
|
|
XA_ATOM, &real, &format, &n, &extra,
|
2007-12-28 20:48:29 +01:00
|
|
|
(unsigned char **) &data) == Success && data)
|
|
|
|
{
|
|
|
|
state = (Atom *) data;
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
ewmh_process_state_atom(c, state[i], _NET_WM_STATE_ADD);
|
|
|
|
|
|
|
|
XFree(data);
|
|
|
|
}
|
2007-12-27 22:39:29 +01:00
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
if(XGetWindowProperty(globalconf.display, c->win, net_wm_window_type, 0L, LONG_MAX, False,
|
|
|
|
XA_ATOM, &real, &format, &n, &extra,
|
|
|
|
(unsigned char **) &data) == Success && data)
|
|
|
|
{
|
|
|
|
state = (Atom *) data;
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
ewmh_process_window_type_atom(c, state[i]);
|
2007-12-27 22:39:29 +01:00
|
|
|
|
2007-12-28 20:48:29 +01:00
|
|
|
XFree(data);
|
|
|
|
}
|
2007-12-27 20:49:38 +01:00
|
|
|
}
|
|
|
|
|
2008-01-03 19:02:23 +01:00
|
|
|
NetWMIcon *
|
|
|
|
ewmh_get_window_icon(Window w)
|
|
|
|
{
|
|
|
|
NetWMIcon *icon;
|
|
|
|
Atom type;
|
|
|
|
int format, size, i;
|
|
|
|
unsigned long items, rest, *data, pixel;
|
|
|
|
unsigned char *imgdata, *wdata;
|
|
|
|
|
|
|
|
if(XGetWindowProperty(globalconf.display, w,
|
|
|
|
net_wm_icon, 0L, LONG_MAX, False, XA_CARDINAL, &type, &format,
|
|
|
|
&items, &rest, &wdata) != Success
|
|
|
|
|| !wdata)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(type != XA_CARDINAL || format != 32 || items < 2)
|
|
|
|
{
|
|
|
|
XFree(wdata);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon = p_new(NetWMIcon, 1);
|
|
|
|
|
|
|
|
data = (unsigned long *) wdata;
|
|
|
|
|
|
|
|
icon->width = data[0];
|
|
|
|
icon->height = data[1];
|
|
|
|
size = icon->width * icon->height;
|
|
|
|
|
|
|
|
if(!size)
|
|
|
|
{
|
|
|
|
p_delete(&icon);
|
|
|
|
XFree(wdata);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon->image = p_new(unsigned char, size * 4);
|
|
|
|
for(imgdata = icon->image, i = 2; i < size + 2; i++, imgdata += 4)
|
|
|
|
{
|
|
|
|
pixel = data[i];
|
|
|
|
imgdata[3] = (pixel >> 24) & 0xff; /* A */
|
|
|
|
imgdata[0] = (pixel >> 16) & 0xff; /* R */
|
|
|
|
imgdata[1] = (pixel >> 8) & 0xff; /* G */
|
|
|
|
imgdata[2] = pixel & 0xff; /* B */
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(wdata);
|
|
|
|
|
|
|
|
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
|