merge in netwm branch at tag netwm-merge2

This commit is contained in:
Dana Jansens 2002-05-30 06:51:43 +00:00
parent 23640740ca
commit 5336c900d0
7 changed files with 155 additions and 166 deletions

View file

@ -137,7 +137,7 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
xatom->setSupported(this); // set-up netwm support xatom->setSupported(this); // set-up netwm support
#ifdef HAVE_GETPID #ifdef HAVE_GETPID
xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::Type_Cardinal, xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
(unsigned long) getpid()); (unsigned long) getpid());
#endif // HAVE_GETPID #endif // HAVE_GETPID
@ -230,10 +230,16 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
} }
saveWorkspaceNames(); saveWorkspaceNames();
updateNetizenWorkspaceCount();
workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu); workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
workspacemenu->update(); workspacemenu->update();
current_workspace = workspacesList.front(); current_workspace = workspacesList.front();
xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
XAtom::cardinal, 0); //first workspace
workspacemenu->setItemSelected(2, True); workspacemenu->setItemSelected(2, True);
toolbar = new Toolbar(this); toolbar = new Toolbar(this);
@ -1020,6 +1026,10 @@ void BScreen::changeWorkspaceID(unsigned int id) {
current_workspace = getWorkspace(id); current_workspace = getWorkspace(id);
xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
XAtom::cardinal, id);
printf("%d\n", id);
workspacemenu->setItemSelected(current_workspace->getID() + 2, True); workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
toolbar->redrawWorkspaceLabel(True); toolbar->redrawWorkspaceLabel(True);
@ -1107,6 +1117,9 @@ void BScreen::removeNetizen(Window w) {
} }
xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
XAtom::cardinal, workspacesList.size());
void BScreen::updateNetizenCurrentWorkspace(void) { void BScreen::updateNetizenCurrentWorkspace(void) {
std::for_each(netizenList.begin(), netizenList.end(), std::for_each(netizenList.begin(), netizenList.end(),
std::mem_fun(&Netizen::sendCurrentWorkspace)); std::mem_fun(&Netizen::sendCurrentWorkspace));

View file

@ -75,6 +75,7 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
blackbox = b; blackbox = b;
client.window = w; client.window = w;
screen = s; screen = s;
xatom = blackbox->getXAtom();
if (! validateClient()) { if (! validateClient()) {
delete this; delete this;
@ -1758,14 +1759,10 @@ void BlackboxWindow::setState(unsigned long new_state) {
unsigned long state[2]; unsigned long state[2];
state[0] = current_state; state[0] = current_state;
state[1] = None; state[1] = None;
XChangeProperty(blackbox->getXDisplay(), client.window, xatom->setValue(client.window, XAtom::wm_state, XAtom::wm_state, state, 2);
blackbox->getWMStateAtom(), blackbox->getWMStateAtom(), 32,
PropModeReplace, (unsigned char *) state, 2); xatom->setValue(client.window, XAtom::blackbox_attributes,
XAtom::blackbox_attributes, (unsigned long *)&blackbox_attrib,
XChangeProperty(blackbox->getXDisplay(), client.window,
blackbox->getBlackboxAttributesAtom(),
blackbox->getBlackboxAttributesAtom(), 32, PropModeReplace,
(unsigned char *) &blackbox_attrib,
PropBlackboxAttributesElements); PropBlackboxAttributesElements);
} }
@ -1775,27 +1772,16 @@ bool BlackboxWindow::getState(void) {
Atom atom_return; Atom atom_return;
bool ret = False; bool ret = False;
int foo; unsigned long *state, nitems;
unsigned long *state, ulfoo, nitems;
if ((XGetWindowProperty(blackbox->getXDisplay(), client.window, if (! xatom->getValue(client.window, XAtom::wm_state, XAtom::wm_state, nitems,
blackbox->getWMStateAtom(), &state))
0l, 2l, False, blackbox->getWMStateAtom(),
&atom_return, &foo, &nitems, &ulfoo,
(unsigned char **) &state) != Success) ||
(! state)) {
return False; return False;
}
if (nitems >= 1) { current_state = static_cast<unsigned long>(state[0]);
current_state = static_cast<unsigned long>(state[0]); delete state;
ret = True; return True;
}
XFree((void *) state);
return ret;
} }

View file

@ -111,6 +111,7 @@ public:
private: private:
Blackbox *blackbox; Blackbox *blackbox;
BScreen *screen; BScreen *screen;
XAtom *xatom;
BTimer *timer; BTimer *timer;
BlackboxAttributes blackbox_attrib; BlackboxAttributes blackbox_attrib;

View file

@ -32,6 +32,11 @@ XAtom::XAtom(Blackbox *bb) {
// make sure asserts fire if there is a problem // make sure asserts fire if there is a problem
memset(_atoms, sizeof(_atoms), 0); memset(_atoms, sizeof(_atoms), 0);
_atoms[cardinal] = XA_CARDINAL;
_atoms[window] = XA_WINDOW;
_atoms[pixmap] = XA_PIXMAP;
_atoms[atom] = XA_ATOM;
_atoms[string] = XA_STRING;
_atoms[utf8_string] = create("UTF8_STRING"); _atoms[utf8_string] = create("UTF8_STRING");
#ifdef HAVE_GETPID #ifdef HAVE_GETPID
@ -132,40 +137,38 @@ void XAtom::setSupported(const ScreenInfo *screen) {
_support_windows.push_back(w); _support_windows.push_back(w);
// set supporting window // set supporting window
setValue(root, net_supporting_wm_check, Type_Window, w); setValue(root, net_supporting_wm_check, window, w);
//set properties on the supporting window //set properties on the supporting window
setValue(w, net_wm_name, Type_Utf8, "Openbox"); setValue(w, net_wm_name, utf8, "Openbox");
setValue(w, net_supporting_wm_check, Type_Window, w); setValue(w, net_supporting_wm_check, window, w);
// we don't support any yet.. // we don't support any yet..
// yes we do! // yes we do!
Atom supported[] = { Atom supported[] = {
_atoms[net_supported] // remove me later, cuz i dont think i belong _atoms[net_current_desktop],
_atoms[net_number_of_desktops]
}; };
const int num_supported = sizeof(supported)/sizeof(Atom);
eraseValue(root, net_supported); setValue(root, net_supported, atom, supported, num_supported);
for (unsigned int i = 0, num = sizeof(supported)/sizeof(Atom); i < num; ++i)
addValue(root, net_supported, Type_Atom, supported[i]);
} }
/* /*
* Internal setValue used by all typed setValue functions. * Internal setValue.
* Sets a window property on a window, optionally appending to the existing * Sets a window property on a window, optionally appending to the existing
* value. * value.
*/ */
void XAtom::setValue(Window win, AvailableAtoms atom, Atom type, void XAtom::setValue(Window win, Atom atom, Atom type,
unsigned char* data, int size, int nelements, unsigned char* data, int size, int nelements,
bool append) const { bool append) const {
assert(atom >= 0 && atom < NUM_ATOMS); assert(win != None); assert(atom != None); assert(type != None);
assert(win != None); assert(type != None);
assert(data != (unsigned char *) 0); assert(data != (unsigned char *) 0);
assert(size == 8 || size == 16 || size == 32); assert(size == 8 || size == 16 || size == 32);
assert(nelements > 0); assert(nelements > 0);
XChangeProperty(_display, win, _atoms[atom], type, size, XChangeProperty(_display, win, atom, type, size,
(append ? PropModeAppend : PropModeReplace), (append ? PropModeAppend : PropModeReplace),
data, nelements); data, nelements);
} }
@ -174,75 +177,55 @@ void XAtom::setValue(Window win, AvailableAtoms atom, Atom type,
/* /*
* Set a 32-bit property value on a window. * Set a 32-bit property value on a window.
*/ */
void XAtom::setValue(Window win, AvailableAtoms atom, AtomType type, void XAtom::setValue(Window win, Atoms atom, Atoms type,
unsigned long value) const { unsigned long value) const {
Atom t; assert(atom >= 0 && atom < NUM_ATOMS);
switch (type) { assert(type >= 0 && type < NUM_ATOMS);
case Type_Cardinal: t = XA_CARDINAL; break; setValue(win, _atoms[atom], _atoms[type],
case Type_Atom: t = XA_ATOM; break; reinterpret_cast<unsigned char*>(&value), 32, 1, false);
case Type_Window: t = XA_WINDOW; break;
case Type_Pixmap: t = XA_PIXMAP; break;
default: assert(false); // unhandled AtomType
}
setValue(win, atom, t, reinterpret_cast<unsigned char*>(&value),
32, 1, false);
} }
/* /*
* Set a string property value on a window. * Set an array of 32-bit properties value on a window.
*/ */
void XAtom::setValue(Window win, AvailableAtoms atom, StringType type, void XAtom::setValue(Window win, Atoms atom, Atoms type,
unsigned long value[], int elements) const {
assert(atom >= 0 && atom < NUM_ATOMS);
assert(type >= 0 && type < NUM_ATOMS);
setValue(win, _atoms[atom], _atoms[type],
reinterpret_cast<unsigned char*>(value), 32, elements, false);
}
/*
* Set an string property value on a window.
*/
void XAtom::setValue(Window win, Atoms atom, StringType type,
const std::string &value) const { const std::string &value) const {
Atom t; assert(atom >= 0 && atom < NUM_ATOMS);
switch (type) { assert(type >= 0 && type < NUM_STRING_TYPE);
case Type_String: t = XA_STRING; break; assert(win != None); assert(_atoms[atom] != None);
case Type_Utf8: t = _atoms[utf8_string]; break;
default: assert(false); // unhandled StringType const char *c = value.c_str();
XTextProperty textprop;
if (Success != XmbTextListToTextProperty(_display, const_cast<char**>(&c), 1,
type == ansi ? XStringStyle :
#ifdef X_HAVE_UTF8_STRING
XUTF8StringStyle,
#else
XCompoundTextStyle,
#endif
&textprop)) {
return;
} }
setValue(win, atom, t,
const_cast<unsigned char*> XSetTextProperty(_display, win, &textprop, _atoms[atom]);
(reinterpret_cast<const unsigned char*>(value.c_str())),
8, value.size(), false); XFree(textprop.value);
} }
/*
* Add elements to a 32-bit property value on a window.
*/
void XAtom::addValue(Window win, AvailableAtoms atom, AtomType type,
unsigned long value) const {
Atom t;
switch (type) {
case Type_Cardinal: t = XA_CARDINAL; break;
case Type_Atom: t = XA_ATOM; break;
case Type_Window: t = XA_WINDOW; break;
case Type_Pixmap: t = XA_PIXMAP; break;
default: assert(false); // unhandled Atom_Type
}
setValue(win, atom, t, reinterpret_cast<unsigned char*>(&value), 32, 1, true);
}
/*
* Add characters to a string property value on a window.
*/
void XAtom::addValue(Window win, AvailableAtoms atom, StringType type,
const std::string &value) const {
Atom t;
switch (type) {
case Type_String: t = XA_STRING; break;
case Type_Utf8: t = _atoms[utf8_string]; break;
default: assert(false); // unhandled StringType
}
setValue(win, atom, t,
const_cast<unsigned char*>
(reinterpret_cast<const unsigned char *>
(value.c_str())),
8, value.size(), true);
}
/* /*
* Internal getValue function used by all of the typed getValue functions. * Internal getValue function used by all of the typed getValue functions.
* Gets an property's value from a window. * Gets an property's value from a window.
@ -250,19 +233,18 @@ void XAtom::addValue(Window win, AvailableAtoms atom, StringType type,
* property did not exist on the window, or has a different type/size format * property did not exist on the window, or has a different type/size format
* than the user tried to retrieve. * than the user tried to retrieve.
*/ */
bool XAtom::getValue(Window win, AvailableAtoms atom, Atom type, bool XAtom::getValue(Window win, Atom atom, Atom type,
unsigned long *nelements, unsigned char **value, unsigned long &nelements, unsigned char **value,
int size) const { int size) const {
assert(atom >= 0 && atom < NUM_ATOMS); assert(win != None); assert(atom != None); assert(type != None);
assert(win != None); assert(type != None);
assert(size == 8 || size == 16 || size == 32); assert(size == 8 || size == 16 || size == 32);
unsigned char *c_val; // value alloc'd with c malloc unsigned char *c_val; // value alloc'd with c malloc
Atom ret_type; Atom ret_type;
int ret_size; int ret_size;
unsigned long ret_bytes; unsigned long ret_bytes;
XGetWindowProperty(_display, win, _atoms[atom], 0l, 1l, False, // try get the first element
AnyPropertyType, &ret_type, &ret_size, nelements, XGetWindowProperty(_display, win, atom, 0l, 1l, False, AnyPropertyType,
&ret_bytes, &c_val); // try get the first element &ret_type, &ret_size, &nelements, &ret_bytes, &c_val);
if (ret_type == None) if (ret_type == None)
// the property does not exist on the window // the property does not exist on the window
return false; return false;
@ -274,8 +256,8 @@ bool XAtom::getValue(Window win, AvailableAtoms atom, Atom type,
// the data is correct, now, is there more than 1 element? // the data is correct, now, is there more than 1 element?
if (ret_bytes == 0) { if (ret_bytes == 0) {
// we got the whole property's value // we got the whole property's value
*value = new unsigned char[*nelements * size/8 + 1]; *value = new unsigned char[nelements * size/8 + 1];
memcpy(*value, c_val, *nelements * size/8 + 1); memcpy(*value, c_val, nelements * size/8 + 1);
XFree(c_val); XFree(c_val);
return true; return true;
} }
@ -284,11 +266,11 @@ bool XAtom::getValue(Window win, AvailableAtoms atom, Atom type,
// the number of longs that need to be retreived to get the property's entire // the number of longs that need to be retreived to get the property's entire
// value. The last + 1 is the first long that we retrieved above. // value. The last + 1 is the first long that we retrieved above.
const int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1; const int remain = (ret_bytes - 1)/sizeof(long) + 1 + 1;
XGetWindowProperty(_display, win, _atoms[atom], 0l, remain, False, type, XGetWindowProperty(_display, win, atom, 0l, remain, False, type, &ret_type,
&ret_type, &ret_size, nelements, &ret_bytes, &c_val); &ret_size, &nelements, &ret_bytes, &c_val);
assert(ret_bytes == 0); assert(ret_bytes == 0);
*value = new unsigned char[*nelements * size/8 + 1]; *value = new unsigned char[nelements * size/8 + 1];
memcpy(*value, c_val, *nelements * size/8 + 1); memcpy(*value, c_val, nelements * size/8 + 1);
XFree(c_val); XFree(c_val);
return true; return true;
} }
@ -297,18 +279,12 @@ bool XAtom::getValue(Window win, AvailableAtoms atom, Atom type,
/* /*
* Gets a 32-bit property's value from a window. * Gets a 32-bit property's value from a window.
*/ */
bool XAtom::getValue(Window win, AvailableAtoms atom, AtomType type, bool XAtom::getValue(Window win, Atoms atom, Atoms type,
unsigned long *nelements, unsigned long &nelements,
unsigned long **value) const { unsigned long **value) const {
Atom t; assert(atom >= 0 && atom < NUM_ATOMS);
switch (type) { assert(type >= 0 && type < NUM_ATOMS);
case Type_Cardinal: t = XA_CARDINAL; break; return getValue(win, _atoms[atom], _atoms[type], nelements,
case Type_Atom: t = XA_ATOM; break;
case Type_Window: t = XA_WINDOW; break;
case Type_Pixmap: t = XA_PIXMAP; break;
default: assert(false); // unhandled Atom_Type
}
return getValue(win, atom, XA_CARDINAL, nelements,
reinterpret_cast<unsigned char **>(value), 32); reinterpret_cast<unsigned char **>(value), 32);
} }
@ -316,26 +292,48 @@ bool XAtom::getValue(Window win, AvailableAtoms atom, AtomType type,
/* /*
* Gets an string property's value from a window. * Gets an string property's value from a window.
*/ */
bool XAtom::getValue(Window win, AvailableAtoms atom, StringType type, bool XAtom::getValue(Window win, Atoms atom, StringType type,
std::string &value) const { std::string &value) const {
Atom t; assert(atom >= 0 && atom < NUM_ATOMS);
switch (type) { assert(type >= 0 && type < NUM_STRING_TYPE);
case Type_String: t = XA_STRING; break; assert(win != None); assert(_atoms[atom] != None);
case Type_Utf8: t = _atoms[utf8_string]; break;
default: assert(false); // unhandled StringType XTextProperty textprop;
if (0 == XGetTextProperty(_display, win, &textprop, _atoms[atom]))
return false;
int ret;
int count;
char **list;
if (type == ansi) {
ret = XmbTextPropertyToTextList(_display, &textprop, &list, &count);
} else {
#ifdef X_HAVE_UTF8_STRING
ret = Xutf8TextPropertyToTextList(_display, &textprop, &list, &count);
#else
ret = XmbTextPropertyToTextList(_display, &textprop, &list, &count);
#endif
} }
unsigned char *data;
unsigned long nelements; if (ret != Success || count < 1) {
bool ret = getValue(win, atom, t, &nelements, &data, 8); XFree(textprop.value);
if (ret) return false;
value = reinterpret_cast<char*>(data); }
return ret;
value = list[0];
XFreeStringList(list);
XFree(textprop.value);
return true;
} }
/* /*
* Removes a property entirely from a window. * Removes a property entirely from a window.
*/ */
void XAtom::eraseValue(Window win, AvailableAtoms atom) const { void XAtom::eraseValue(Window win, Atoms atom) const {
assert(atom >= 0 && atom < NUM_ATOMS);
XDeleteProperty(_display, win, _atoms[atom]); XDeleteProperty(_display, win, _atoms[atom]);
} }

View file

@ -32,8 +32,13 @@ class ScreenInfo;
class XAtom { class XAtom {
public: public:
enum AvailableAtoms { enum Atoms {
// string type // types
cardinal,
window,
pixmap,
atom,
string,
utf8_string, utf8_string,
#ifdef HAVE_GETPID #ifdef HAVE_GETPID
@ -102,16 +107,10 @@ public:
NUM_ATOMS NUM_ATOMS
}; };
enum AtomType {
Type_Cardinal,
Type_Atom,
Type_Window,
Type_Pixmap
};
enum StringType { enum StringType {
Type_String, ansi,
Type_Utf8, utf8,
NUM_STRING_TYPE
}; };
private: private:
@ -124,10 +123,10 @@ private:
Atom create(const char *name) const; Atom create(const char *name) const;
void setValue(Window win, AvailableAtoms atom, Atom type, unsigned char *data, void setValue(Window win, Atom atom, Atom type, unsigned char *data,
int size, int nelements, bool append) const; int size, int nelements, bool append) const;
bool getValue(Window win, AvailableAtoms atom, Atom type, bool getValue(Window win, Atom atom, Atom type,
unsigned long *nelements, unsigned char **value, unsigned long &nelements, unsigned char **value,
int size) const; int size) const;
// no copying!! // no copying!!
@ -142,29 +141,25 @@ public:
// constructor. // constructor.
void setSupported(const ScreenInfo *screen); void setSupported(const ScreenInfo *screen);
void setValue(Window win, AvailableAtoms atom, AtomType type, void setValue(Window win, Atoms atom, Atoms type, unsigned long value) const;
unsigned long value) const; void setValue(Window win, Atoms atom, Atoms type,
void setValue(Window win, AvailableAtoms atom, StringType type, unsigned long value[], int elements) const;
const std::string &value) const; void setValue(Window win, Atoms atom, StringType type,
void addValue(Window win, AvailableAtoms atom, AtomType type,
unsigned long value) const;
void addValue(Window win, AvailableAtoms atom, StringType type,
const std::string &value) const; const std::string &value) const;
// the 'value' is allocated inside the function and // the 'value' is allocated inside the function and
// delete [] value needs to be called when you are done with it. // delete [] value needs to be called when you are done with it.
// the 'value' array returned is null terminated, and has 'nelements' // the 'value' array returned is null terminated, and has 'nelements'
// elements in it plus the null. // elements in it plus the null.
bool getValue(Window win, AvailableAtoms atom, AtomType type, bool getValue(Window win, Atoms atom, Atoms type,
unsigned long *nelements, unsigned long **value) const; unsigned long &nelements, unsigned long **value) const;
bool getValue(Window win, AvailableAtoms atom, StringType type, bool getValue(Window win, Atoms atom, StringType type,
std::string &value) const; std::string &value) const;
void eraseValue(Window win, AvailableAtoms atom) const; void eraseValue(Window win, Atoms atom) const;
// temporary function!! remove when not used in blackbox.hh anymore!! // temporary function!! remove when not used in blackbox.hh anymore!!
inline Atom getAtom(AvailableAtoms a) inline Atom getAtom(Atoms a)
{ Atom ret = _atoms[a]; assert(ret != 0); return ret; } { Atom ret = _atoms[a]; assert(ret != 0); return ret; }
}; };

View file

@ -653,7 +653,7 @@ void Blackbox::process_event(XEvent *e) {
case ClientMessage: { case ClientMessage: {
if (e->xclient.format == 32) { if (e->xclient.format == 32) {
if (e->xclient.message_type == getWMChangeStateAtom()) { if (e->xclient.message_type == xatom->getAtom(XAtom::wm_change_state)) {
BlackboxWindow *win = searchWindow(e->xclient.window); BlackboxWindow *win = searchWindow(e->xclient.window);
if (! win || ! win->validateClient()) return; if (! win || ! win->validateClient()) return;

View file

@ -245,10 +245,6 @@ public:
enum { B_AmericanDate = 1, B_EuropeanDate }; enum { B_AmericanDate = 1, B_EuropeanDate };
#endif // HAVE_STRFTIME #endif // HAVE_STRFTIME
inline Atom getWMChangeStateAtom(void) const
{ return xatom->getAtom(XAtom::wm_change_state); }
inline Atom getWMStateAtom(void) const
{ return xatom->getAtom(XAtom::wm_state); }
inline Atom getWMDeleteAtom(void) const inline Atom getWMDeleteAtom(void) const
{ return xatom->getAtom(XAtom::wm_delete_window); } { return xatom->getAtom(XAtom::wm_delete_window); }
inline Atom getWMProtocolsAtom(void) const inline Atom getWMProtocolsAtom(void) const