From d4f33533543690f12ad9eea62ea9b634a89340fb Mon Sep 17 00:00:00 2001 From: markt Date: Thu, 5 Apr 2007 16:05:39 +0000 Subject: some minor changes and reorganization --- src/FbCommandFactory.cc | 2 +- src/FbTk/KeyUtil.cc | 14 +++++------- src/FbTk/KeyUtil.hh | 4 ++-- src/FbWinFrame.cc | 33 ++++++++-------------------- src/FbWinFrame.hh | 17 +++++---------- src/IconButton.cc | 44 +++++++++++++++++++++++++++++++++---- src/IconButton.hh | 6 +++++ src/IconbarTool.cc | 58 +++---------------------------------------------- src/IconbarTool.hh | 4 ---- src/MenuCreator.cc | 3 ++- src/WinClient.cc | 7 ++++++ src/WinClient.hh | 1 + 12 files changed, 83 insertions(+), 110 deletions(-) diff --git a/src/FbCommandFactory.cc b/src/FbCommandFactory.cc index dc1d9e9..5a97e05 100644 --- a/src/FbCommandFactory.cc +++ b/src/FbCommandFactory.cc @@ -317,7 +317,7 @@ FbTk::Command *FbCommandFactory::stringToCommand(const std::string &command, FbTk::RefCount cmd; if (command == "resizeto") cmd = new ResizeToCmd(dx, dy); - else if (command == "resizeto") + else cmd = new ResizeCmd(dx, dy); return new WindowListCmd(cmd, pat); diff --git a/src/FbTk/KeyUtil.cc b/src/FbTk/KeyUtil.cc index 6985139..abf91fe 100644 --- a/src/FbTk/KeyUtil.cc +++ b/src/FbTk/KeyUtil.cc @@ -62,7 +62,7 @@ KeyUtil &KeyUtil::instance() { KeyUtil::KeyUtil() - : m_modmap(0), m_capslock(0), m_numlock(0), m_scrolllock(0) + : m_modmap(0), m_numlock(0), m_scrolllock(0) { init(); } @@ -93,9 +93,9 @@ void KeyUtil::loadModmap() { m_modmap->modifiermap[realkey], 0); switch (ks) { - case XK_Caps_Lock: - m_capslock = modlist[i].mask; - break; + // we just want to clean the Lock modifier, not specifically the + // XK_Caps_Lock key + // the others tend to vary from distro to distro, though case XK_Scroll_Lock: m_scrolllock = modlist[i].mask; break; @@ -114,13 +114,12 @@ void KeyUtil::loadModmap() { */ void KeyUtil::grabKey(unsigned int key, unsigned int mod, Window win) { Display *display = App::instance()->display(); - const unsigned int capsmod = instance().capslock(); const unsigned int nummod = instance().numlock(); const unsigned int scrollmod = instance().scrolllock(); // Grab with numlock, capslock and scrlock for (int i = 0; i < 8; i++) { - XGrabKey(display, key, mod | (i & 1 ? capsmod : 0) | + XGrabKey(display, key, mod | (i & 1 ? LockMask : 0) | (i & 2 ? nummod : 0) | (i & 4 ? scrollmod : 0), win, True, GrabModeAsync, GrabModeAsync); } @@ -130,13 +129,12 @@ void KeyUtil::grabKey(unsigned int key, unsigned int mod, Window win) { void KeyUtil::grabButton(unsigned int button, unsigned int mod, Window win, unsigned int event_mask, Cursor cursor) { Display *display = App::instance()->display(); - const unsigned int capsmod = instance().capslock(); const unsigned int nummod = instance().numlock(); const unsigned int scrollmod = instance().scrolllock(); // Grab with numlock, capslock and scrlock for (int i = 0; i < 8; i++) { - XGrabButton(display, button, mod | (i & 1 ? capsmod : 0) | + XGrabButton(display, button, mod | (i & 1 ? LockMask : 0) | (i & 2 ? nummod : 0) | (i & 4 ? scrollmod : 0), win, False, event_mask, GrabModeAsync, GrabModeAsync, None, cursor); diff --git a/src/FbTk/KeyUtil.hh b/src/FbTk/KeyUtil.hh index 4909c5a..e80918a 100644 --- a/src/FbTk/KeyUtil.hh +++ b/src/FbTk/KeyUtil.hh @@ -87,14 +87,14 @@ public: */ static unsigned int keycodeToModmask(unsigned int keycode); int numlock() const { return m_numlock; } - int capslock() const { return m_capslock; } + int capslock() const { return LockMask; } int scrolllock() const { return m_scrolllock; } private: void loadModmap(); XModifierKeymap *m_modmap; - int m_capslock, m_numlock, m_scrolllock; + int m_numlock, m_scrolllock; static std::auto_ptr s_keyutil; }; diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index 238cfb6..cbfd0f8 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -692,7 +692,7 @@ void FbWinFrame::moveLabelButtonRightOf(FbTk::TextButton &btn, const FbTk::TextB m_tab_container.moveItem(&btn, movement); } -void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) { +void FbWinFrame::setLabelButtonFocus(IconButton &btn) { if (&btn == currentLabel() || btn.parent() != &m_tab_container) return; @@ -709,7 +709,7 @@ void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn) { applyUnfocusLabel(*m_current_label); } -void FbWinFrame::setLabelButtonFocus(FbTk::TextButton &btn, bool value) { +void FbWinFrame::setLabelButtonFocus(IconButton &btn, bool value) { if (btn.parent() != &m_tab_container) return; @@ -1307,14 +1307,6 @@ void FbWinFrame::renderTabContainer() { m_tabcontainer_unfocused_pm, m_tab_container.width(), m_tab_container.height(), m_tab_container.orientation()); - render(m_theme.iconbarTheme().focusedTexture(), m_labelbutton_focused_color, - m_labelbutton_focused_pm, - m_tab_container.width(), m_tab_container.height(), m_tab_container.orientation()); - - render(m_theme.iconbarTheme().unfocusedTexture(), m_labelbutton_unfocused_color, - m_labelbutton_unfocused_pm, - m_tab_container.width(), m_tab_container.height(), m_tab_container.orientation()); - renderButtons(); } @@ -1464,7 +1456,6 @@ void FbWinFrame::init() { m_title_focused_pm = m_title_unfocused_pm = 0; m_label_focused_pm = m_label_unfocused_pm = 0; m_tabcontainer_focused_pm = m_tabcontainer_unfocused_pm = 0; - m_labelbutton_focused_pm = m_labelbutton_unfocused_pm = 0; m_handle_focused_pm = m_handle_unfocused_pm = 0; m_button_pm = m_button_unfocused_pm = m_button_pressed_pm = 0; m_grip_unfocused_pm = m_grip_focused_pm = 0; @@ -1587,7 +1578,7 @@ void FbWinFrame::applyTabContainer() { Container::ItemList::iterator btn_it = m_tab_container.begin(); Container::ItemList::iterator btn_it_end = m_tab_container.end(); for (; btn_it != btn_it_end; ++btn_it) { - FbTk::TextButton *btn = static_cast(*btn_it); + IconButton *btn = static_cast(*btn_it); if (btn == m_current_label && m_focused) applyFocusLabel(*btn); else @@ -1649,31 +1640,25 @@ void FbWinFrame::setBorderWidth(unsigned int border_width) { } -void FbWinFrame::applyFocusLabel(FbTk::TextButton &button) { +void FbWinFrame::applyFocusLabel(IconButton &button) { button.setGC(theme().iconbarTheme().focusedText().textGC()); button.setFont(theme().iconbarTheme().focusedText().font()); button.setJustify(theme().justify()); button.setAlpha(getAlpha(m_focused)); - - if (m_labelbutton_focused_pm != 0) { - button.setBackgroundPixmap(m_labelbutton_focused_pm); - } else - button.setBackgroundColor(m_labelbutton_focused_color); + button.renderTextures(); + button.updateBackground(); } -void FbWinFrame::applyUnfocusLabel(FbTk::TextButton &button) { +void FbWinFrame::applyUnfocusLabel(IconButton &button) { button.setGC(theme().iconbarTheme().unfocusedText().textGC()); button.setFont(theme().iconbarTheme().unfocusedText().font()); button.setJustify(theme().justify()); button.setAlpha(getAlpha(m_focused)); - - if (m_labelbutton_unfocused_pm != 0) { - button.setBackgroundPixmap(m_labelbutton_unfocused_pm); - } else - button.setBackgroundColor(m_labelbutton_unfocused_color); + button.renderTextures(); + button.updateBackground(); } diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index ff8df83..503317a 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -155,9 +155,9 @@ public: //move the first label button to the right of the second void moveLabelButtonRightOf(FbTk::TextButton &btn, const FbTk::TextButton &dest); /// which button is to be rendered focused - void setLabelButtonFocus(FbTk::TextButton &btn); + void setLabelButtonFocus(IconButton &btn); /// specify focus state of button - void setLabelButtonFocus(FbTk::TextButton &btn, bool value); + void setLabelButtonFocus(IconButton &btn, bool value); /// attach a client window for client area void setClientWindow(FbTk::FbWindow &win); /// remove attached client window @@ -233,7 +233,7 @@ public: inline FbTk::FbWindow &gripLeft() { return m_grip_left; } inline const FbTk::FbWindow &gripRight() const { return m_grip_right; } inline FbTk::FbWindow &gripRight() { return m_grip_right; } - inline const FbTk::TextButton *currentLabel() const { return m_current_label; } + inline const IconButton *currentLabel() const { return m_current_label; } inline bool focused() const { return m_focused; } inline bool isShaded() const { return m_shaded; } inline FbWinFrameTheme &theme() const { return m_theme; } @@ -279,8 +279,8 @@ private: void applyTitlebar(); void applyHandles(); void applyTabContainer(); // and label buttons - void applyFocusLabel(FbTk::TextButton &button); - void applyUnfocusLabel(FbTk::TextButton &button); + void applyFocusLabel(IconButton &button); + void applyUnfocusLabel(IconButton &button); void applyButtons(); // only called within applyTitlebar void getCurrentFocusPixmap(Pixmap &label_pm, Pixmap &title_pm, @@ -319,7 +319,7 @@ private: ButtonList m_buttons_left, ///< buttons to the left m_buttons_right; ///< buttons to the right typedef std::list LabelList; - FbTk::TextButton *m_current_label; ///< which client button is focused at the moment + IconButton *m_current_label; ///< which client button is focused at the moment int m_bevel; ///< bevel between titlebar items and titlebar bool m_use_titlebar; ///< if we should use titlebar bool m_use_tabs; ///< if we should use tabs (turns them off in external mode only) @@ -348,11 +348,6 @@ private: Pixmap m_tabcontainer_unfocused_pm; ///< pixmap for unfocused tab container FbTk::Color m_tabcontainer_unfocused_color; ///< color for unfocused tab container - Pixmap m_labelbutton_focused_pm; ///< pixmap for focused label - FbTk::Color m_labelbutton_focused_color; ///< color for focused label - Pixmap m_labelbutton_unfocused_pm; ///< pixmap for unfocused label - FbTk::Color m_labelbutton_unfocused_color; ///< color for unfocused label - FbTk::Color m_handle_focused_color, m_handle_unfocused_color; Pixmap m_handle_focused_pm, m_handle_unfocused_pm; diff --git a/src/IconButton.cc b/src/IconButton.cc index b884fbb..8830b93 100644 --- a/src/IconButton.cc +++ b/src/IconButton.cc @@ -30,12 +30,13 @@ #include "Focusable.hh" #include "FbTk/App.hh" -#include "FbTk/SimpleCommand.hh" +#include "FbTk/Command.hh" #include "FbTk/EventManager.hh" +#include "FbTk/ImageControl.hh" #include "FbTk/MacroCommand.hh" -#include "FbTk/Command.hh" -#include "FbTk/RefCount.hh" #include "FbTk/Menu.hh" +#include "FbTk/RefCount.hh" +#include "FbTk/SimpleCommand.hh" #ifdef HAVE_CONFIG_H #include "config.h" @@ -54,7 +55,9 @@ IconButton::IconButton(const FbTk::FbWindow &parent, IconbarTheme &theme, m_icon_window(*this, 1, 1, 1, 1, ExposureMask | ButtonPressMask | ButtonReleaseMask), m_use_pixmap(true), - m_theme(theme) { + m_theme(theme), + m_focused_pm(win.screen().imageControl()), + m_unfocused_pm(win.screen().imageControl()) { m_win.titleSig().attach(this); @@ -112,6 +115,39 @@ void IconButton::setPixmap(bool use) { } } +void IconButton::updateBackground() { + // TODO: this ignores attention state, which isn't in Focusable.hh yet + if (m_win.isFocused()) { + if (m_focused_pm != 0) + setBackgroundPixmap(m_focused_pm); + else + setBackgroundColor(m_theme.focusedTexture().color()); + } else { + if (m_unfocused_pm != 0) + setBackgroundPixmap(m_unfocused_pm); + else + setBackgroundColor(m_theme.unfocusedTexture().color()); + } +} + +void IconButton::renderTextures() { + + if (m_theme.focusedTexture().usePixmap()) + m_focused_pm.reset(m_win.screen().imageControl().renderImage( + width(), height(), m_theme.focusedTexture(), + orientation())); + else + m_focused_pm.reset(0); + + if (m_theme.unfocusedTexture().usePixmap()) + m_unfocused_pm.reset(m_win.screen().imageControl().renderImage( + width(), height(), m_theme.unfocusedTexture(), + orientation())); + else + m_unfocused_pm.reset( 0 ); + +} + void IconButton::update(FbTk::Subject *subj) { // we got signal that either title or // icon pixmap was updated, diff --git a/src/IconButton.hh b/src/IconButton.hh index b724084..2c48bff 100644 --- a/src/IconButton.hh +++ b/src/IconButton.hh @@ -25,6 +25,7 @@ #ifndef ICONBUTTON_HH #define ICONBUTTON_HH +#include "FbTk/CachedPixmap.hh" #include "FbTk/FbPixmap.hh" #include "FbTk/Observer.hh" #include "FbTk/TextButton.hh" @@ -47,6 +48,9 @@ public: unsigned int width, unsigned int height); void resize(unsigned int width, unsigned int height); + void renderTextures(); + void updateBackground(); + void update(FbTk::Subject *subj); void setPixmap(bool use); @@ -67,6 +71,8 @@ private: bool m_use_pixmap; IconbarTheme &m_theme; + // cached pixmaps + FbTk::CachedPixmap m_focused_pm, m_unfocused_pm; }; #endif // ICONBUTTON_HH diff --git a/src/IconbarTool.cc b/src/IconbarTool.cc index 42d5782..ef99c9a 100644 --- a/src/IconbarTool.cc +++ b/src/IconbarTool.cc @@ -401,10 +401,6 @@ IconbarTool::IconbarTool(const FbTk::FbWindow &parent, IconbarTheme &theme, BScr m_screen(screen), m_icon_container(parent), m_theme(theme), - m_focused_pm( screen.imageControl() ), - m_unfocused_pm( screen.imageControl() ), - m_focused_err_pm( screen.imageControl() ), - m_unfocused_err_pm( screen.imageControl() ), m_empty_pm( screen.imageControl() ), m_rc_mode(screen.resourceManager(), WORKSPACE, screen.name() + ".iconbar.mode", screen.altName() + ".Iconbar.Mode"), @@ -694,32 +690,6 @@ void IconbarTool::renderTheme() { icon_height_off = 1; } - if (!m_theme.focusedTexture().usePixmap()) { - m_focused_pm.reset( 0 ); - m_focused_err_pm.reset( 0 ); - } else { - m_focused_pm.reset( m_screen.imageControl(). - renderImage(icon_width, icon_height, - m_theme.focusedTexture(), orientation()) ); - m_focused_err_pm.reset( m_screen.imageControl(). - renderImage(icon_width + icon_width_off, - icon_height + icon_height_off, - m_theme.focusedTexture(), orientation()) ); - } - - if (!m_theme.unfocusedTexture().usePixmap()) { - m_unfocused_pm.reset( 0 ); - m_unfocused_err_pm.reset( 0 ); - } else { - m_unfocused_pm.reset( m_screen.imageControl(). - renderImage(icon_width, icon_height, - m_theme.unfocusedTexture(), orientation()) ); - m_unfocused_err_pm.reset( m_screen.imageControl(). - renderImage(icon_width+icon_width_off, - icon_height+icon_height_off, - m_theme.unfocusedTexture(), orientation()) ); - } - // if we dont have any icons then we should render empty texture if (!m_theme.emptyTexture().usePixmap()) { m_empty_pm.reset( 0 ); @@ -747,22 +717,11 @@ void IconbarTool::renderTheme() { void IconbarTool::renderButton(IconButton &button, bool clear, int focusOption) { + button.renderTextures(); button.setPixmap(*m_rc_use_pixmap); button.setAlpha(m_alpha); button.setTextPadding(*m_rc_client_padding); - // The last button is always the regular width - bool wider_button = false; - if (!m_icon_container.empty()) { - if (button.orientation() == FbTk::ROT0 || button.orientation() == FbTk::ROT180) - wider_button = button.width() != m_icon_container.back()->width(); - else - wider_button = button.height() != m_icon_container.back()->height(); -// wider_button = (button.width() != m_icon_container.maxWidthPerClient() || // height to cover both orients - -// button.height() != m_icon_container.back()->height()); - } - if (focusOption == 1 || (focusOption == -1 && button.win().isFocused())) { @@ -776,13 +735,7 @@ void IconbarTool::renderButton(IconButton &button, bool clear, button.setJustify(m_theme.focusedText().justify()); button.setBorderWidth(m_theme.focusedBorder().width()); button.setBorderColor(m_theme.focusedBorder().color()); - - if (!wider_button && m_focused_pm != 0) - button.setBackgroundPixmap(m_focused_pm); - else if (wider_button && m_focused_err_pm != 0) - button.setBackgroundPixmap(m_focused_err_pm); - else - button.setBackgroundColor(m_theme.focusedTexture().color()); + button.updateBackground(); } else { // unfocused if (m_icon_container.selected() == &button) @@ -793,13 +746,8 @@ void IconbarTool::renderButton(IconButton &button, bool clear, button.setJustify(m_theme.unfocusedText().justify()); button.setBorderWidth(m_theme.unfocusedBorder().width()); button.setBorderColor(m_theme.unfocusedBorder().color()); + button.updateBackground(); - if (!wider_button && m_unfocused_pm != 0) - button.setBackgroundPixmap(m_unfocused_pm); - else if (wider_button && m_unfocused_err_pm != 0) - button.setBackgroundPixmap(m_unfocused_err_pm); - else - button.setBackgroundColor(m_theme.unfocusedTexture().color()); } if (clear) diff --git a/src/IconbarTool.hh b/src/IconbarTool.hh index 7662e72..d7a9c09 100644 --- a/src/IconbarTool.hh +++ b/src/IconbarTool.hh @@ -122,10 +122,6 @@ private: BScreen &m_screen; Container m_icon_container; IconbarTheme &m_theme; - // cached pixmaps - FbTk::CachedPixmap m_focused_pm, m_unfocused_pm; - // some are a fraction bigger due to rounding - FbTk::CachedPixmap m_focused_err_pm, m_unfocused_err_pm; FbTk::CachedPixmap m_empty_pm; ///< pixmap for empty container diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc index e24693e..d973a66 100644 --- a/src/MenuCreator.cc +++ b/src/MenuCreator.cc @@ -465,8 +465,9 @@ FbTk::Menu *MenuCreator::createFromFile(const string &filename, int screen_numbe bool MenuCreator::createFromFile(const string &filename, FbTk::Menu &inject_into, bool require_begin) { - string real_filename = FbTk::StringUtil::expandFilename(filename); + Fluxbox::instance()->saveMenuFilename(real_filename.c_str()); + FbMenuParser parser(real_filename); if (!parser.isLoaded()) return false; diff --git a/src/WinClient.cc b/src/WinClient.cc index de6c213..1cdd4ae 100644 --- a/src/WinClient.cc +++ b/src/WinClient.cc @@ -25,6 +25,7 @@ #include "Window.hh" #include "fluxbox.hh" +#include "FocusControl.hh" #include "Screen.hh" #include "FbAtoms.hh" @@ -716,6 +717,12 @@ bool WinClient::focus() { return fbwindow()->setCurrentClient(*this, true); } +bool WinClient::isFocused() const { + return (fbwindow() ? + fbwindow()->isFocused() && &fbwindow()->winClient() == this : + false); +} + void WinClient::updateWMProtocols() { Atom *proto = 0; int num_return = 0; diff --git a/src/WinClient.hh b/src/WinClient.hh index 534a2a5..6b22b49 100644 --- a/src/WinClient.hh +++ b/src/WinClient.hh @@ -82,6 +82,7 @@ public: void clearStrut(); bool focus(); // calls Window->setCurrentClient to give focus to this client + bool isFocused() const; const std::string &title() const; /** -- cgit v0.11.2