Can check CARDINAL properties in CLIENT PATTERNS

Introduces a new member function, FbWindow::cardinalProperty()

This change also changes other code that previously used
FbWindow::property() to do the same thing as the new function; this
reduces code duplication.

There are still some bits of code (Ewmh.cc, extractNetWmIcon()) that use
FbWindow::property() to retrieve XA_CARDINAL values, but as the new
method is designed for getting a _single_ property, and that code uses
FbWindow::property() to retrieve the number of values present, and then
grab all of them; it's a different use case.  I opted to not try to make
cardinalProperty() into some monolithic all-purpose cardinal method;
FbWindow::property() works just fine for that.

This change also adds an optional (default=NULL) boolean to
FbWindow::textProperty and friends that allows the caller to determine
whether or not a value was actually retrieved.  This was necessary for
integrating FbWindow::cardinalProperty with the codebase, and it seemed
to fit with FbWindow::textProperty as well.  Prior to this change, if
you got a return value of "", you wouldn't know if you successfully
retrieved the value which happened to be blank, or if you failed to
retrieve the value.  Now, you can pass the address of a boolean if you
so choose in order to differentiate these situations; the same applies
to the new FbWindow::cardinalProperty().
This commit is contained in:
nacitar sevaht 2011-05-07 21:38:13 -05:00 committed by Mathias Gumz
parent 2f166eb4ae
commit 1dacf57d20
10 changed files with 69 additions and 63 deletions

View file

@ -322,7 +322,7 @@ bool ClientPattern::match(const Focusable &win) const {
for (; it != it_end; ++it) {
const Term& term = *(*it);
if (term.prop == XPROP) {
if (!term.negate ^ (term.regexp.match(win.getTextProperty(term.xprop))))
if (!term.negate ^ ((term.regexp.match(win.getTextProperty(term.xprop))) || term.regexp.match(FbTk::StringUtil::number2String(win.getCardinalProperty(term.xprop)))))
return false;
} else if (term.regstr == "[current]") {
WinClient *focused = FocusControl::focusedWindow();

View file

@ -695,22 +695,13 @@ void Ewmh::setupClient(WinClient &winclient) {
void Ewmh::setupFrame(FluxboxWindow &win) {
setupState(win);
Atom ret_type;
int fmt;
unsigned long nitems, bytes_after;
unsigned char *data = 0;
if (win.winClient().property(m_net->wm_desktop, 0, 1, False, XA_CARDINAL,
&ret_type, &fmt, &nitems, &bytes_after,
(unsigned char **) &data) && data) {
unsigned int desktop = static_cast<long>(*data);
bool exists;
unsigned int desktop=static_cast<unsigned int>(win.winClient().cardinalProperty(m_net->wm_desktop, &exists));
if (exists) {
if (desktop == (unsigned int)(-1) && !win.isStuck())
win.stick();
else
win.setWorkspace(desktop);
XFree(data);
} else {
updateWorkspace(win);
}

View file

@ -41,6 +41,8 @@
#include <assert.h>
#endif
#include <limits>
namespace FbTk {
FbWindow::FbWindow():
@ -483,29 +485,45 @@ struct TextPropPtr {
};
}
std::string FbWindow::textProperty(Atom property) const {
long FbWindow::cardinalProperty(Atom prop,bool*exists) const {
Atom type;
int format;
unsigned long nitems, bytes_after;
int result;
long* num;
long ret=0;
if (exists) *exists=false;
if (property(prop, 0, 1, False, XA_CARDINAL, &type, &format, &nitems, &bytes_after, reinterpret_cast<unsigned char**>(&num))) {
if (type == XA_CARDINAL && nitems) {
ret = *num;
if (exists) *exists=true;
}
XFree(num);
}
return ret;
}
FbTk::FbString FbWindow::textProperty(Atom prop,bool*exists) const {
XTextProperty text_prop;
TextPropPtr helper(text_prop);
char ** stringlist = 0;
int count = 0;
std::string ret;
FbTk::FbString ret;
static Atom m_utf8string = XInternAtom(display(), "UTF8_STRING", False);
static const Atom utf8string = XInternAtom(display(), "UTF8_STRING", False);
if (XGetTextProperty(display(), window(), &text_prop, property) == 0) {
if (exists) *exists=false;
if (XGetTextProperty(display(), window(), &text_prop, prop) == 0 || text_prop.value == 0 || text_prop.nitems == 0) {
return "";
}
if (text_prop.value == 0 || text_prop.nitems == 0) {
return "";
}
if (text_prop.encoding == XA_STRING) {
if (XTextPropertyToStringList(&text_prop, &stringlist, &count) == 0 || count == 0) {
return "";
}
ret = FbStringUtil::XStrToFb(stringlist[0]);
} else if (text_prop.encoding == m_utf8string && text_prop.format == 8) {
} else if (text_prop.encoding == utf8string && text_prop.format == 8) {
#ifdef X_HAVE_UTF8_STRING
Xutf8TextPropertyToTextList(display(), &text_prop, &stringlist, &count);
if (count == 0 || stringlist == 0) {
@ -530,11 +548,11 @@ std::string FbWindow::textProperty(Atom property) const {
if (stringlist) {
XFreeStringList(stringlist);
}
if (exists) *exists=true;
return ret;
}
bool FbWindow::property(Atom property,
bool FbWindow::property(Atom prop,
long long_offset, long long_length,
bool do_delete,
Atom req_type,
@ -544,7 +562,7 @@ bool FbWindow::property(Atom property,
unsigned long *bytes_after_return,
unsigned char **prop_return) const {
if (XGetWindowProperty(display(), window(),
property, long_offset, long_length, do_delete,
prop, long_offset, long_length, do_delete,
req_type, actual_type_return,
actual_format_return, nitems_return,
bytes_after_return, prop_return) == Success)
@ -553,19 +571,19 @@ bool FbWindow::property(Atom property,
return false;
}
void FbWindow::changeProperty(Atom property, Atom type,
void FbWindow::changeProperty(Atom prop, Atom type,
int format,
int mode,
unsigned char *data,
int nelements) {
XChangeProperty(display(), m_window, property, type,
XChangeProperty(display(), m_window, prop, type,
format, mode,
data, nelements);
}
void FbWindow::deleteProperty(Atom property) {
XDeleteProperty(display(), m_window, property);
void FbWindow::deleteProperty(Atom prop) {
XDeleteProperty(display(), m_window, prop);
}
void FbWindow::addToSaveSet() {
@ -590,9 +608,9 @@ long FbWindow::eventMask() const {
void FbWindow::setOpaque(int alpha) {
#ifdef HAVE_XRENDER
static Atom m_alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False);
static const Atom alphaatom = XInternAtom(display(), "_NET_WM_WINDOW_OPACITY", False);
unsigned long opacity = alpha * 0x1010101;
changeProperty(m_alphaatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1l);
changeProperty(alphaatom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1l);
#endif // HAVE_XRENDER
}

View file

@ -23,7 +23,7 @@
#define FBTK_FBWINDOW_HH
#include "FbDrawable.hh"
#include "FbString.hh"
#include <memory>
#include <string>
#include <set>
@ -158,7 +158,8 @@ public:
void deleteProperty(Atom property);
std::string textProperty(Atom property) const;
long cardinalProperty(Atom property,bool*exists=NULL) const;
FbTk::FbString textProperty(Atom property,bool*exists=NULL) const;
void addToSaveSet();
void removeFromSaveSet();

View file

@ -88,7 +88,8 @@ public:
/// @return wm role string (for pattern matching)
virtual std::string getWMRole() const { return "Focusable"; }
virtual FbTk::FbString getTextProperty(Atom prop) const { return ""; }
virtual FbTk::FbString getTextProperty(Atom prop,bool*exists=NULL) const { return ""; }
virtual long getCardinalProperty(Atom prop,bool*exists=NULL) const { return 0; }
/// @return whether this window is a transient (for pattern matching)
virtual bool isTransient() const { return false; }

View file

@ -98,40 +98,30 @@ void Gnome::initForScreen(BScreen &screen) {
void Gnome::setupFrame(FluxboxWindow &win) {
// load gnome state (take queues from the main window of the frame)
Atom ret_type;
int fmt;
unsigned long nitems, bytes_after;
long flags, *data = 0;
if (win.winClient().property(m_gnome_wm_win_state, 0, 1, False, XA_CARDINAL,
&ret_type, &fmt, &nitems, &bytes_after,
(unsigned char **) &data) && data) {
flags = *data;
long flags;
bool exists;
flags=win.winClient().cardinalProperty(m_gnome_wm_win_state,&exists);
if (exists) {
setState(&win, flags);
XFree (data);
} else {
updateState(win);
}
// load gnome layer atom
if (win.winClient().property(m_gnome_wm_win_layer, 0, 1, False, XA_CARDINAL,
&ret_type, &fmt, &nitems, &bytes_after,
(unsigned char **) &data) && data) {
flags = *data;
flags=win.winClient().cardinalProperty(m_gnome_wm_win_layer,&exists);
if (exists) {
setLayer(&win, flags);
XFree (data);
} else {
updateLayer(win);
}
// load gnome workspace atom
if (win.winClient().property(m_gnome_wm_win_workspace, 0, 1, False, XA_CARDINAL,
&ret_type, &fmt, &nitems, &bytes_after,
(unsigned char **) &data) && data) {
unsigned int workspace_num = *data;
flags=win.winClient().cardinalProperty(m_gnome_wm_win_workspace,&exists);
if (exists)
{
unsigned int workspace_num = flags;
if (win.workspaceNumber() != workspace_num)
win.setWorkspace(workspace_num);
XFree (data);
} else {
updateWorkspace(win);
}

View file

@ -477,12 +477,11 @@ BScreen::BScreen(FbTk::ResourceManager &rm,
unsigned int first_desktop = 0;
if (m_restart) {
Atom net_desktop = XInternAtom(disp, "_NET_CURRENT_DESKTOP", False);
if (rootWindow().property(net_desktop, 0l, 1l,
False, XA_CARDINAL, &xa_ret_type, &ret_format, &ret_nitems,
&ret_bytes_after, &ret_prop) == Success) {
if (ret_prop && static_cast<unsigned int>(*ret_prop) < static_cast<unsigned int>(nr_ws))
first_desktop = static_cast<unsigned int>(*ret_prop);
XFree(ret_prop);
bool exists;
unsigned int ret=static_cast<unsigned int>(rootWindow().cardinalProperty(net_desktop, &exists));
if (exists) {
if (ret < static_cast<unsigned int>(nr_ws))
first_desktop = ret;
}
}

View file

@ -96,7 +96,8 @@ public:
std::string getWMRole() const;
WindowState::WindowType getWindowType() const { return m_window_type; }
void setWindowType(WindowState::WindowType type) { m_window_type = type; }
FbTk::FbString getTextProperty(Atom prop) const { return FbTk::FbWindow::textProperty(prop); }
long getCardinalProperty(Atom prop,bool*exists=NULL) const { return FbTk::FbWindow::cardinalProperty(prop,exists); }
FbTk::FbString getTextProperty(Atom prop,bool*exists=NULL) const { return FbTk::FbWindow::textProperty(prop,exists); }
WinClient *transientFor() { return transient_for; }
const WinClient *transientFor() const { return transient_for; }

View file

@ -3342,8 +3342,12 @@ FbTk::FbString FluxboxWindow::getWMRole() const {
return (m_client ? m_client->getWMRole() : "FluxboxWindow");
}
FbTk::FbString FluxboxWindow::getTextProperty(Atom prop) const {
return (m_client ? m_client->getTextProperty(prop) : Focusable::getTextProperty(prop));
long FluxboxWindow::getCardinalProperty(Atom prop,bool*exists) const {
return (m_client ? m_client->getCardinalProperty(prop,exists) : Focusable::getCardinalProperty(prop,exists));
}
FbTk::FbString FluxboxWindow::getTextProperty(Atom prop,bool*exists) const {
return (m_client ? m_client->getTextProperty(prop,exists) : Focusable::getTextProperty(prop,exists));
}
bool FluxboxWindow::isTransient() const {

View file

@ -422,7 +422,8 @@ public:
const FbTk::FbString &getWMClassName() const;
const FbTk::FbString &getWMClassClass() const;
std::string getWMRole() const;
FbTk::FbString getTextProperty(Atom prop) const;
long getCardinalProperty(Atom prop,bool*exists=NULL) const;
FbTk::FbString getTextProperty(Atom prop,bool*exists=NULL) const;
void setWindowType(WindowState::WindowType type);
bool isTransient() const;