Use common netwm code from edelib.

This commit is contained in:
Sanel Zukan
2009-12-24 15:47:29 +00:00
parent 66da6a79b6
commit 44d997a075
4 changed files with 48 additions and 216 deletions

View File

@@ -10,21 +10,12 @@
* See COPYING for details.
*/
#include <string.h> // strrchr, strncpy, strlen
#include <X11/Xproto.h> // CARD32
#include <string.h>
#include <FL/x.H>
#include <edelib/Debug.h>
#include "Utils.h"
Atom _XA_NET_WORKAREA = 0;
Atom _XA_NET_WM_WINDOW_TYPE = 0;
Atom _XA_NET_WM_WINDOW_TYPE_DESKTOP = 0;
Atom _XA_NET_NUMBER_OF_DESKTOPS = 0;
Atom _XA_NET_CURRENT_DESKTOP = 0;
Atom _XA_NET_DESKTOP_NAMES = 0;
Atom _XA_XROOTPMAP_ID = 0;
static int overlay_x = 0;
static int overlay_y = 0;
static int overlay_w = 0;
@@ -34,156 +25,6 @@ static Fl_Window* overlay_drawable = NULL;
static char dash_list[] = {1};
void init_atoms(void) {
_XA_NET_WORKAREA = XInternAtom(fl_display, "_NET_WORKAREA", False);
_XA_NET_WM_WINDOW_TYPE = XInternAtom(fl_display, "_NET_WM_WINDOW_TYPE", False);
_XA_NET_WM_WINDOW_TYPE_DESKTOP = XInternAtom(fl_display, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
_XA_NET_NUMBER_OF_DESKTOPS = XInternAtom(fl_display, "_NET_NUMBER_OF_DESKTOPS", False);
_XA_NET_CURRENT_DESKTOP = XInternAtom(fl_display, "_NET_CURRENT_DESKTOP", False);
_XA_NET_DESKTOP_NAMES = XInternAtom(fl_display, "_NET_DESKTOP_NAMES", False);
_XA_XROOTPMAP_ID = XInternAtom(fl_display, "_XROOTPMAP_ID", False);
}
bool net_get_workarea(int& x, int& y, int& w, int &h) {
Atom real;
int format;
unsigned long n, extra;
unsigned char* prop;
x = y = w = h = 0;
int status = XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
_XA_NET_WORKAREA, 0L, 0x7fffffff, False, XA_CARDINAL, &real, &format, &n, &extra, (unsigned char**)&prop);
if(status != Success)
return false;
CARD32* val = (CARD32*)prop;
if(val) {
x = val[0];
y = val[1];
w = val[2];
h = val[3];
XFree((char*)val);
return true;
}
return false;
}
void net_make_me_desktop(Fl_Window* w) {
/*
* xid() will return zero if window is not shown;
* make sure it is shown
*/
EASSERT(fl_xid(w));
/*
* Reminder for me (others possible):
* note '&_XA_NET_WM_WINDOW_TYPE_DESKTOP' conversion, since gcc will not report warning/error
* if placed '_XA_NET_WM_WINDOW_TYPE_DESKTOP' only.
*
* I lost two hours messing with this ! (gdb is unusefull in X world)
*/
XChangeProperty(fl_display, fl_xid(w), _XA_NET_WM_WINDOW_TYPE, XA_ATOM, 32, PropModeReplace,
(unsigned char*)&_XA_NET_WM_WINDOW_TYPE_DESKTOP, sizeof(Atom));
}
int net_get_workspace_count(void) {
Atom real;
int format;
unsigned long n, extra;
unsigned char* prop;
int status = XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
_XA_NET_NUMBER_OF_DESKTOPS, 0L, 0x7fffffff, False, XA_CARDINAL, &real, &format, &n, &extra,
(unsigned char**)&prop);
if(status != Success && !prop)
return -1;
int ns = int(*(long*)prop);
XFree(prop);
return ns;
}
// desktops are starting from 0
int net_get_current_desktop(void) {
Atom real;
int format;
unsigned long n, extra;
unsigned char* prop;
int status = XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
_XA_NET_CURRENT_DESKTOP, 0L, 0x7fffffff, False, XA_CARDINAL, &real, &format, &n, &extra,
(unsigned char**)&prop);
if(status != Success && !prop)
return -1;
int ns = int(*(long*)prop);
XFree(prop);
return ns;
}
// call on this XFreeStringList(names)
int net_get_workspace_names(char**& names) {
// FIXME: add _NET_SUPPORTING_WM_CHECK and _NET_SUPPORTED ???
XTextProperty wnames;
XGetTextProperty(fl_display, RootWindow(fl_display, fl_screen), &wnames, _XA_NET_DESKTOP_NAMES);
// if wm does not understainds _NET_DESKTOP_NAMES this is not set
if(!wnames.nitems || !wnames.value)
return 0;
int nsz;
/*
* FIXME: Here should as alternative Xutf8TextPropertyToTextList since
* many wm's set UTF8_STRING property. Below is XA_STRING and for UTF8_STRING
* will fail.
*/
if(!XTextPropertyToStringList(&wnames, &names, &nsz)) {
XFree(wnames.value);
return 0;
}
XFree(wnames.value);
return nsz;
}
#if 0
int net_get_workspace_names(char** names) {
Atom nd = XInternAtom(fl_display, "_NET_DESKTOP_NAMES", False);
Atom utf8_str = XInternAtom(fl_display, "UTF8_STRING", False);
Atom real;
int format;
unsigned long n, extra;
unsigned char* prop;
int status = XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
nd, 0L, 0x7fffffff, False, utf8_str, &real, &format, &n, &extra, (unsigned char**)&prop);
if(status != Success && !prop)
return 0;
int alloc = 0;
if(real == utf8_str && format == 8) {
const char* p = (const char*)prop;
for(int i = 0, s = 0; i < n && alloc < MAX_DESKTOPS; i++, alloc++) {
if(p[i] == '\0') {
E_DEBUG("%c ", p[i]);
names[alloc] = strndup((p + s), i - s + 1);
s = i + 1;
}
}
}
return alloc;
}
#endif
void draw_overlay_rect(void) {
if(overlay_w <= 0 || overlay_h <= 0)
return;
@@ -203,7 +44,7 @@ void draw_overlay_rect(void) {
XSetFunction(fl_display, fl_gc, GXcopy);
// set line to 0 again
/* set line to 0 again */
XSetLineAttributes(fl_display, fl_gc, 0, LineOnOffDash, CapButt, JoinMiter);
}
@@ -249,7 +90,7 @@ Pixmap create_mask(Fl_Image* img) {
if(!img)
return 0;
// no alpha
/* no alpha */
if(img->d() != 4)
return 0;
@@ -269,16 +110,16 @@ Pixmap create_mask(Fl_Image* img) {
for(int y = 0; y < ih; y++) {
for(int x = 0; x < iw; x++) {
// jump rgb and pick alpha
/* jump rgb and pick alpha */
src += 3;
a = *src++;
if(a < 128) {
// these are transparent
/* these are transparent */
XPutPixel(xim, x, y, 0);
}
else {
// these are opaque
/* these are opaque */
XPutPixel(xim, x, y, 1);
}
}