2007-10-13 21:51:37 +00:00
|
|
|
// Focusable.hh
|
|
|
|
// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef FOCUSABLE_HH
|
|
|
|
#define FOCUSABLE_HH
|
|
|
|
|
|
|
|
#include "FbTk/PixmapWithMask.hh"
|
|
|
|
#include "FbTk/ITypeAheadable.hh"
|
2010-03-18 18:41:35 +00:00
|
|
|
#include "FbTk/Signal.hh"
|
2010-09-08 18:17:21 +00:00
|
|
|
#include "FbTk/FbString.hh"
|
2007-10-13 21:51:37 +00:00
|
|
|
|
|
|
|
class BScreen;
|
|
|
|
class FluxboxWindow;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Base class for any object that might be "focused".
|
|
|
|
* Such as FluxboxWindow, Menu etc
|
|
|
|
*/
|
|
|
|
class Focusable: public FbTk::ITypeAheadable {
|
|
|
|
public:
|
|
|
|
Focusable(BScreen &scr, FluxboxWindow *fbwin = 0):
|
|
|
|
m_screen(scr), m_fbwin(fbwin),
|
|
|
|
m_instance_name("fluxbox"), m_class_name("fluxbox"),
|
|
|
|
m_focused(false), m_attention_state(false),
|
2011-05-07 20:03:08 +00:00
|
|
|
m_attentionsig(),
|
2010-03-26 17:15:45 +00:00
|
|
|
m_focussig(),
|
2011-05-03 21:48:24 +00:00
|
|
|
m_diesig(),
|
2010-03-26 17:15:45 +00:00
|
|
|
m_titlesig() { }
|
2007-10-13 21:51:37 +00:00
|
|
|
virtual ~Focusable() { }
|
2007-11-05 17:05:58 +00:00
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
/**
|
|
|
|
* Take focus.
|
|
|
|
* @return true if the focuable took focus
|
|
|
|
*/
|
|
|
|
virtual bool focus() { return false; }
|
|
|
|
|
|
|
|
/// @return true if the focusable has input focus
|
|
|
|
virtual bool isFocused() const { return m_focused; }
|
2012-07-07 02:30:39 +00:00
|
|
|
/// @return true if it can be focused
|
2007-10-13 21:51:37 +00:00
|
|
|
virtual bool acceptsFocus() const { return true; }
|
2012-07-07 02:30:39 +00:00
|
|
|
/// @return true if temporarily prevented from being focused
|
|
|
|
virtual bool isModal() const { return false; }
|
2007-10-13 21:51:37 +00:00
|
|
|
|
|
|
|
/// @return true if icon button should appear focused
|
2007-12-29 21:38:53 +00:00
|
|
|
bool getAttentionState() const { return m_attention_state; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/// @set the attention state
|
|
|
|
virtual void setAttentionState(bool value) {
|
2011-05-07 20:03:08 +00:00
|
|
|
m_attention_state = value; attentionSig().emit(*this);
|
2007-10-13 21:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @return the screen in which this object resides
|
2007-12-29 21:38:53 +00:00
|
|
|
BScreen &screen() { return m_screen; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/// @return the screen in which this object resides
|
2007-12-29 21:38:53 +00:00
|
|
|
const BScreen &screen() const { return m_screen; }
|
2007-10-13 21:51:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For accessing window properties, like shaded, minimized, etc.
|
|
|
|
* @return window context
|
|
|
|
*/
|
2007-12-29 21:38:53 +00:00
|
|
|
const FluxboxWindow *fbwindow() const { return m_fbwin; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/**
|
|
|
|
* For accessing window properties, like shaded, minimized, etc.
|
|
|
|
* @return window context
|
|
|
|
*/
|
2007-12-29 21:38:53 +00:00
|
|
|
FluxboxWindow *fbwindow() { return m_fbwin; }
|
2007-10-13 21:51:37 +00:00
|
|
|
|
|
|
|
/// @return WM_CLASS class string (for pattern matching)
|
2010-09-08 18:17:21 +00:00
|
|
|
virtual const FbTk::FbString &getWMClassClass() const { return m_class_name; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/// @return WM_CLASS name string (for pattern matching)
|
2010-09-08 18:17:21 +00:00
|
|
|
virtual const FbTk::FbString &getWMClassName() const { return m_instance_name; }
|
2007-10-14 18:05:31 +00:00
|
|
|
/// @return wm role string (for pattern matching)
|
2007-10-13 21:51:37 +00:00
|
|
|
virtual std::string getWMRole() const { return "Focusable"; }
|
|
|
|
|
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().
2011-05-08 02:38:13 +00:00
|
|
|
virtual FbTk::FbString getTextProperty(Atom prop,bool*exists=NULL) const { return ""; }
|
|
|
|
virtual long getCardinalProperty(Atom prop,bool*exists=NULL) const { return 0; }
|
2010-09-11 15:09:07 +00:00
|
|
|
|
2007-10-14 18:05:31 +00:00
|
|
|
/// @return whether this window is a transient (for pattern matching)
|
|
|
|
virtual bool isTransient() const { return false; }
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
// so we can make nice buttons, menu entries, etc.
|
|
|
|
/// @return icon pixmap of the focusable
|
|
|
|
virtual const FbTk::PixmapWithMask &icon() const { return m_icon; }
|
|
|
|
/// @return title string
|
2010-09-08 18:17:21 +00:00
|
|
|
virtual const FbTk::BiDiString &title() const { return m_title; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/// @return type ahead string
|
2010-09-08 18:17:21 +00:00
|
|
|
const std::string &iTypeString() const { return title().logical(); }
|
2007-10-13 21:51:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@name signals
|
|
|
|
@{
|
|
|
|
*/
|
2011-05-03 10:49:05 +00:00
|
|
|
typedef FbTk::Signal<const std::string&, Focusable&> TitleSignal;
|
2010-03-26 17:15:45 +00:00
|
|
|
/// Used for both title and icon changes.
|
|
|
|
TitleSignal &titleSig() { return m_titlesig; }
|
|
|
|
/// Used for both title and icon changes.
|
|
|
|
const TitleSignal &titleSig() const { return m_titlesig; }
|
2011-05-03 10:49:05 +00:00
|
|
|
FbTk::Signal<Focusable&> &focusSig() { return m_focussig; }
|
2011-05-03 21:48:24 +00:00
|
|
|
FbTk::Signal<Focusable&> &dieSig() { return m_diesig; }
|
2011-05-07 20:03:08 +00:00
|
|
|
FbTk::Signal<Focusable&> &attentionSig() { return m_attentionsig; }
|
2007-10-13 21:51:37 +00:00
|
|
|
/** @} */ // end group signals
|
|
|
|
|
2010-03-18 18:41:35 +00:00
|
|
|
/// Notify any listeners that the focus changed for this window.
|
|
|
|
void notifyFocusChanged() {
|
|
|
|
m_focussig.emit(*this);
|
|
|
|
}
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
protected:
|
|
|
|
BScreen &m_screen; //< the screen in which it works
|
|
|
|
FluxboxWindow *m_fbwin; //< the working fluxbox window
|
|
|
|
|
2010-09-08 18:17:21 +00:00
|
|
|
FbTk::BiDiString m_title;
|
|
|
|
FbTk::FbString m_instance_name;
|
|
|
|
FbTk::FbString m_class_name;
|
|
|
|
|
2007-10-13 21:51:37 +00:00
|
|
|
bool m_focused; //< whether or not it has focus
|
|
|
|
bool m_attention_state; //< state of icon button while demanding attention
|
|
|
|
FbTk::PixmapWithMask m_icon; //< icon pixmap with mask
|
|
|
|
|
2010-03-18 18:41:35 +00:00
|
|
|
|
|
|
|
private:
|
2011-05-07 20:03:08 +00:00
|
|
|
FbTk::Signal<Focusable&> m_attentionsig;
|
2011-05-03 10:49:05 +00:00
|
|
|
FbTk::Signal<Focusable&> m_focussig;
|
2011-05-03 21:48:24 +00:00
|
|
|
FbTk::Signal<Focusable&> m_diesig;
|
2010-03-26 17:15:45 +00:00
|
|
|
TitleSignal m_titlesig;
|
2007-10-13 21:51:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FOCUSABLE_HH
|