From 51bcee666516ffdbe205b0e74ca209f82fcb1f31 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 21 Mar 2007 21:48:34 +0000 Subject: added Focusable.hh -- a base class for all focusable windows --- src/CommandDialog.cc | 2 +- src/FocusControl.cc | 2 +- src/Focusable.hh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Screen.cc | 6 +++--- src/WinClient.cc | 35 ++++++++++++++----------------- src/WinClient.hh | 18 ++-------------- src/Window.cc | 29 +++++++++++++------------- src/Window.hh | 11 +++++----- 8 files changed, 101 insertions(+), 61 deletions(-) create mode 100644 src/Focusable.hh diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc index e502bc1..3207a48 100644 --- a/src/CommandDialog.cc +++ b/src/CommandDialog.cc @@ -98,7 +98,7 @@ void CommandDialog::hide() { // return focus to fluxbox window if (FocusControl::focusedFbWindow()) - FocusControl::focusedFbWindow()->setInputFocus(); + FocusControl::focusedFbWindow()->focus(); } diff --git a/src/FocusControl.cc b/src/FocusControl.cc index e16cbec..2314f33 100644 --- a/src/FocusControl.cc +++ b/src/FocusControl.cc @@ -363,7 +363,7 @@ void FocusControl::dirFocus(FluxboxWindow &win, FocusDir dir) { } if (foundwin) - foundwin->setInputFocus(); + foundwin->focus(); } diff --git a/src/Focusable.hh b/src/Focusable.hh new file mode 100644 index 0000000..21baffa --- /dev/null +++ b/src/Focusable.hh @@ -0,0 +1,59 @@ +// 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/FbPixmap.hh" + +#include + +class FluxboxWindow; + +// base class for any object that might be "focused" +class Focusable { +public: + Focusable(FluxboxWindow *fbwin = 0): m_fbwin(fbwin) { } + virtual ~Focusable() { } + + virtual bool focus() { return false; } + + // so we can make nice buttons, menu entries, etc. + virtual const FbTk::FbPixmap &iconPixmap() const { return m_icon_pixmap; } + virtual bool usePixmap() const { return iconPixmap().drawable() != None; } + + virtual const FbTk::FbPixmap &iconMask() const { return m_icon_mask; } + virtual bool useMask() const { return iconMask().drawable() != None; } + + virtual const std::string &title() const { return m_title; } + virtual const std::string &iconTitle() const { return m_icon_title; } + + // for accessing window properties, like shaded, minimized, etc. + inline const FluxboxWindow *fbwindow() const { return m_fbwin; } + inline FluxboxWindow *fbwindow() { return m_fbwin; } + +protected: + std::string m_title, m_icon_title; + FbTk::FbPixmap m_icon_pixmap, m_icon_mask; + FluxboxWindow *m_fbwin; +}; + +#endif // FOCUSABLE_HH diff --git a/src/Screen.cc b/src/Screen.cc index 3ef27a6..987bbd0 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -1199,7 +1199,7 @@ void BScreen::changeWorkspaceID(unsigned int id) { currentWorkspace()->showAll(); if (focused && focused->isMoving()) { - focused->setInputFocus(); + focused->focus(); focused->resumeMoving(); } else FocusControl::revertFocus(*this); @@ -1241,7 +1241,7 @@ void BScreen::sendToWorkspace(unsigned int id, FluxboxWindow *win, bool changeWS // change workspace ? if (changeWS && id != currentWorkspace()->workspaceID()) { changeWorkspaceID(id); - win->setInputFocus(); + win->focus(); } } @@ -1520,7 +1520,7 @@ FluxboxWindow *BScreen::createWindow(WinClient &client) { // don't ask me why, but client doesn't seem to keep focus in new window // and we don't seem to get a FocusIn event from setInputFocus if ((focusControl().focusNew() || FocusControl::focusedWindow() == &client) - && win->setInputFocus()) + && win->focus()) FocusControl::setFocusedWindow(&client); m_clientlist_sig.notify(); diff --git a/src/WinClient.cc b/src/WinClient.cc index bb8a25c..83f2af3 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -57,7 +57,8 @@ using std::dec; WinClient::TransientWaitMap WinClient::s_transient_wait; -WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::FbWindow(win), +WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin): + Focusable(fbwin), FbTk::FbWindow(win), transient_for(0), window_group(0), x(0), y(0), old_bw(0), @@ -70,12 +71,10 @@ WinClient::WinClient(Window win, BScreen &screen, FluxboxWindow *fbwin):FbTk::Fb initial_state(0), normal_hint_flags(0), wm_hint_flags(0), - m_win(fbwin), m_modal(0), send_focus_message(false), send_close_message(false), m_win_gravity(0), - m_title(""), m_icon_title(""), m_class_name(""), m_instance_name(""), m_title_override(false), m_icon_title_override(false), @@ -118,8 +117,8 @@ WinClient::~WinClient() { clearStrut(); - if (m_win != 0) - m_win->removeClient(*this); + if (fbwindow() != 0) + fbwindow()->removeClient(*this); // this takes care of any focus issues m_diesig.notify(); @@ -161,8 +160,6 @@ WinClient::~WinClient() { if (window()) fluxbox->removeWindowSearch(window()); - - m_win = 0; } bool WinClient::acceptsFocus() const { @@ -264,9 +261,9 @@ void WinClient::updateWMClassHint() { void WinClient::updateTransientInfo() { #ifdef DEBUG - cerr<<__FUNCTION__<<": m_win = "< TransientList; // this structure only contains 3 elements... the Motif 2.0 structure contains @@ -129,15 +130,6 @@ public: inline bool isModal() const { return m_modal > 0; } - const FbTk::FbPixmap &iconPixmap() const { return m_icon_pixmap; } - const FbTk::FbPixmap &iconMask() const { return m_icon_mask; } - const bool usePixmap() const { return m_icon_pixmap.drawable() != None; } - const bool useMask() const { return m_icon_mask.drawable() != None; } - - inline const std::string &title() const { return m_title; } - inline const std::string &iconTitle() const { return m_icon_title; } - inline const FluxboxWindow *fbwindow() const { return m_win; } - inline FluxboxWindow *fbwindow() { return m_win; } inline int gravity() const { return m_win_gravity; } bool hasGroupLeftWindow() const; @@ -188,8 +180,6 @@ private: /// removes client from any waiting list and clears empty waiting lists void removeTransientFromWaitingList(); - FluxboxWindow *m_win; - // number of transients which we are modal for // or indicates that we are modal if don't have any transients int m_modal; @@ -197,13 +187,9 @@ private: int m_win_gravity; - std::string m_title, m_icon_title; std::string m_class_name, m_instance_name; bool m_title_override, m_icon_title_override; - FbTk::FbPixmap m_icon_pixmap; - FbTk::FbPixmap m_icon_mask; - FluxboxWindow::BlackboxHints *m_blackbox_hint; MwmHints *m_mwm_hint; diff --git a/src/Window.cc b/src/Window.cc index 8e6b887..1eb214a 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -239,6 +239,7 @@ int FluxboxWindow::s_num_grabs = 0; FluxboxWindow::FluxboxWindow(WinClient &client, FbWinFrameTheme &tm, FbTk::XLayer &layer): + Focusable(this), oplock(false), m_hintsig(*this), m_statesig(*this), @@ -988,7 +989,7 @@ bool FluxboxWindow::setCurrentClient(WinClient &client, bool setinput) { // frame focused doesn't necessarily mean input focused frame().setLabelButtonFocus(*m_labelbuttons[m_client]); - if (setinput && setInputFocus()) { + if (setinput && focus()) { return true; } @@ -1319,7 +1320,7 @@ void FluxboxWindow::moveResizeForClient(int new_x, int new_y, // tried. A FocusqIn event should eventually arrive for that // window if it actually got the focus, then setFocusedFlag is called, // which updates all the graphics etc -bool FluxboxWindow::setInputFocus() { +bool FluxboxWindow::focus() { if (((signed) (frame().x() + frame().width())) < 0) { if (((signed) (frame().y() + frame().height())) < 0) { @@ -1523,7 +1524,7 @@ void FluxboxWindow::deiconify(bool reassoc, bool do_raise) { // focus new, OR if it's the only window on the workspace if (was_iconic && (screen().focusControl().focusNew() || screen().currentWorkspace()->numberOfWindows() == 1)) - setInputFocus(); + focus(); oplock = false; @@ -2603,9 +2604,8 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { if (be.button == 1 || (be.button == 3 && be.state == Fluxbox::instance()->getModKey())) { - if ( (! focused) ) { //check focus - setInputFocus(); - } + if (!focused) //check focus + focus(); if (frame().window().window() == be.window || frame().tabcontainer().window() == be.window) { if (screen().clickRaises()) @@ -2994,7 +2994,7 @@ void FluxboxWindow::enterNotifyEvent(XCrossingEvent &ev) { XCheckIfEvent(display, &dummy, queueScanner, (char *) &sa); if ((!sa.leave || sa.inferior) && !screen().focusControl().isCycling() ) { - setInputFocus(); + focus(); } } } @@ -3246,7 +3246,7 @@ void FluxboxWindow::stopMoving(bool interrupted) { if (m_workspace_number != screen().currentWorkspaceID()) { screen().reassociateWindow(this, screen().currentWorkspaceID(), true); frame().show(); - setInputFocus(); + focus(); } } fluxbox->ungrab(); @@ -3282,7 +3282,7 @@ void FluxboxWindow::resumeMoving() { if (m_workspace_number == screen().currentWorkspaceID()) { frame().show(); - setInputFocus(); + focus(); } FbTk::App::instance()->sync(false); @@ -3664,14 +3664,13 @@ FbTk::Menu &FluxboxWindow::menu() { return screen().windowMenu(); } -const FbTk::FbPixmap &FluxboxWindow::iconPixmap() const { return m_client->iconPixmap(); } -const FbTk::FbPixmap &FluxboxWindow::iconMask() const { return m_client->iconMask(); } - -const bool FluxboxWindow::usePixmap() const { - return m_client ? m_client->usePixmap() : false; +const FbTk::FbPixmap &FluxboxWindow::iconPixmap() const { + return m_client->iconPixmap(); } -const bool FluxboxWindow::useMask() const { return m_client->useMask(); } +const FbTk::FbPixmap &FluxboxWindow::iconMask() const { + return m_client->iconMask(); +} const FbTk::Menu &FluxboxWindow::menu() const { return screen().windowMenu(); diff --git a/src/Window.hh b/src/Window.hh index 3206fdd..726b747 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -32,6 +32,7 @@ #include "FbTk/EventHandler.hh" #include "FbTk/XLayerItem.hh" #include "FbWinFrame.hh" +#include "Focusable.hh" #include "WinButton.hh" #include @@ -56,7 +57,7 @@ class Menu; } /// Creates the window frame and handles any window event for it -class FluxboxWindow: public FbTk::EventHandler { +class FluxboxWindow: public Focusable, public FbTk::EventHandler { public: /// Represents certain "preset" sets of decorations. enum Decoration { @@ -192,8 +193,8 @@ public: void moveClientTo(WinClient &win, int x, int y); ClientList::iterator getClientInsertPosition(int x, int y); - bool setInputFocus(); - void raiseAndFocus() { raise(); setInputFocus(); } + bool focus(); + void raiseAndFocus() { raise(); focus(); } void setFocusFlag(bool flag); // map this window void show(); @@ -379,11 +380,9 @@ public: const FbTk::FbPixmap &iconPixmap() const; const FbTk::FbPixmap &iconMask() const; - const bool usePixmap() const; - const bool useMask() const; - const std::string &title() const; const std::string &iconTitle() const; + inline int x() const { return frame().x(); } inline int y() const { return frame().y(); } inline unsigned int width() const { return frame().width(); } -- cgit v0.11.2