diff --git a/src/ClientPattern.cc b/src/ClientPattern.cc index b2ad6914..f49f7fd5 100644 --- a/src/ClientPattern.cc +++ b/src/ClientPattern.cc @@ -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(); diff --git a/src/Ewmh.cc b/src/Ewmh.cc index bab543b1..52568a1c 100644 --- a/src/Ewmh.cc +++ b/src/Ewmh.cc @@ -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(*data); + bool exists; + unsigned int desktop=static_cast(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); } diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc index 00dde669..9fa59fc3 100644 --- a/src/FbTk/FbWindow.cc +++ b/src/FbTk/FbWindow.cc @@ -41,6 +41,8 @@ #include #endif +#include + 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(&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 } diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh index 9e929236..6f6a5589 100644 --- a/src/FbTk/FbWindow.hh +++ b/src/FbTk/FbWindow.hh @@ -23,7 +23,7 @@ #define FBTK_FBWINDOW_HH #include "FbDrawable.hh" - +#include "FbString.hh" #include #include #include @@ -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(); diff --git a/src/Focusable.hh b/src/Focusable.hh index 4583a62d..0aae1a4b 100644 --- a/src/Focusable.hh +++ b/src/Focusable.hh @@ -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; } diff --git a/src/Gnome.cc b/src/Gnome.cc index 91a0aefd..0c3b6f12 100644 --- a/src/Gnome.cc +++ b/src/Gnome.cc @@ -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); } diff --git a/src/Screen.cc b/src/Screen.cc index bf131fba..a8eca726 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -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(*ret_prop) < static_cast(nr_ws)) - first_desktop = static_cast(*ret_prop); - XFree(ret_prop); + bool exists; + unsigned int ret=static_cast(rootWindow().cardinalProperty(net_desktop, &exists)); + if (exists) { + if (ret < static_cast(nr_ws)) + first_desktop = ret; } } diff --git a/src/WinClient.hh b/src/WinClient.hh index 157278e9..5a29a5e2 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -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; } diff --git a/src/Window.cc b/src/Window.cc index 1a5bd91c..369b4802 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -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 { diff --git a/src/Window.hh b/src/Window.hh index bb270602..8f599a4f 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -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;