From 15ce29e15612fe31c754ead6f56faaeec7f06bd4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 1 Nov 2002 01:54:02 +0000 Subject: [PATCH] merging changes in head since the 2_2 branch began --- src/Font.cc | 33 +++++++++++++++++++++++---------- src/Font.hh | 5 ++++- src/Screen.cc | 20 +++++++++++++++++++- src/Window.cc | 28 +++++++++++----------------- util/epist/ChangeLog | 9 +++++++++ util/epist/config.cc | 1 + util/epist/config.hh | 1 + util/epist/epist.1.in | 2 +- util/epist/epistrc.5.in | 11 ++++++++--- util/epist/keytree.cc | 35 ++++++++++++++++++++++------------- util/epist/parser.cc | 31 ++++++++++++++++++++++--------- util/epist/parser.hh | 4 +--- util/epist/screen.cc | 11 +++++++---- util/epist/screen.hh | 1 + 14 files changed, 130 insertions(+), 62 deletions(-) diff --git a/src/Font.cc b/src/Font.cc index e963c38f..8a04abc9 100644 --- a/src/Font.cc +++ b/src/Font.cc @@ -48,7 +48,8 @@ string BFont::_fallback_font = "fixed"; #ifdef XFT BFont::BFont(Display *d, BScreen *screen, const string &family, int size, - bool bold, bool italic, bool shadow, bool antialias) : + bool bold, bool italic, bool shadow, unsigned char offset, + int tint, bool antialias) : _display(d), _screen(screen), _family(family), @@ -58,6 +59,8 @@ BFont::BFont(Display *d, BScreen *screen, const string &family, int size, _italic(italic), _antialias(antialias), _shadow(shadow), + _offset(offset), + _tint(tint), _xftfont(0), _font(0), _fontset(0), @@ -264,19 +267,29 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color, if (_shadow) { XftColor c; - c.color.red = 0; - c.color.green = 0; - c.color.blue = 0; - c.color.alpha = 0x40 | 0x40 << 8; // transparent shadow - c.pixel = BlackPixel(_display, _screen->getScreenNumber()); + if (_tint >= 0) { + c.color.red = 0; + c.color.green = 0; + c.color.blue = 0; + c.color.alpha = 0xffff * _tint/100; // transparent shadow + c.pixel = BlackPixel(_display, _screen->getScreenNumber()); + } else { + c.color.red = 0xffff * -_tint/100; + c.color.green = 0xffff * -_tint/100; + c.color.blue = 0xffff * -_tint/100; + c.color.alpha = 0xffff * -_tint/100; + c.pixel = WhitePixel(_display, _screen->getScreenNumber()); + } #ifdef XFT_UTF8 XftDrawStringUtf8( #else XftDrawString8( #endif - draw, &c, _xftfont, x + 1, _xftfont->ascent + y + 1, - (XftChar8 *) string.c_str(), string.size()); + draw, &c, _xftfont, x + _offset, + _xftfont->ascent + y + _offset, + (XftChar8 *) string.c_str(), + string.size()); } XftColor c; @@ -327,7 +340,7 @@ unsigned int BFont::measureString(const string &string) const { _display, _xftfont, (XftChar8 *) string.c_str(), string.size(), &info); - return info.xOff + (_shadow ? 1 : 0); + return info.xOff + (_shadow ? std::abs(_offset) : 0); } #endif // XFT @@ -346,7 +359,7 @@ unsigned int BFont::height(void) const { #ifdef XFT if (_xftfont) - return _xftfont->height + (_shadow ? 1 : 0); + return _xftfont->height + (_shadow ? std::abs(_offset) : 0); #endif // XFT if (i18n.multibyte()) diff --git a/src/Font.hh b/src/Font.hh index e29f41b1..6f6431ef 100644 --- a/src/Font.hh +++ b/src/Font.hh @@ -72,6 +72,8 @@ private: #ifdef XFT bool _antialias; bool _shadow; + unsigned char _offset; + int _tint; XftFont *_xftfont; @@ -96,7 +98,8 @@ public: #ifdef XFT // loads an Xft font BFont(Display *d, BScreen *screen, const std::string &family, int size, - bool bold, bool italic, bool shadow, bool antialias = True); + bool bold, bool italic, bool shadow, unsigned char offset, + int tint, bool antialias = True); #endif // loads a standard X font BFont(Display *d, BScreen *screen, const std::string &xlfd); diff --git a/src/Screen.cc b/src/Screen.cc index d138ffbf..2351abcc 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -2725,15 +2725,33 @@ BFont *BScreen::readDatabaseFont(const string &rbasename, string family = s; bool bold = False; bool italic = False; + bool dropShadow = False; + if (style.getValue(rbasename + "xft.flags", s)) { if (s.find("bold") != string::npos) bold = True; if (s.find("italic") != string::npos) italic = True; + if (s.find("shadow") != string::npos) + dropShadow = True; + } + + unsigned char offset = 1; + if (style.getValue(rbasename + "xft.shadow.offset", s)) { + offset = atoi(s.c_str()); //doesn't detect errors + if (offset > CHAR_MAX) + offset = 1; } + + unsigned char tint = 0x40; + if (style.getValue(rbasename + "xft.shadow.tint", s)) { + tint = atoi(s.c_str()); + } + BFont *b = new BFont(blackbox->getXDisplay(), this, family, i, bold, - italic, resource.shadow_fonts, resource.aa_fonts); + italic, dropShadow && resource.shadow_fonts, offset, + tint, resource.aa_fonts); if (b->valid()) return b; else diff --git a/src/Window.cc b/src/Window.cc index b321538e..83adf766 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -600,21 +600,17 @@ void BlackboxWindow::decorate(void) { if (needsPressed) { texture = &(screen->getWindowStyle()->b_pressed); - Pixmap pbutton = texture->render(frame.button_w, frame.button_w, - pbutton); - unsigned long pixel; - - if (!pbutton) { - pixel = texture->color().pixel(); - if (needsPressed & 0x1) - frame.pfbutton_pixel = pixel; - if (needsPressed & 0x2) - frame.pubutton_pixel = pixel; - } else { - if (needsPressed & 0x1) - frame.pfbutton = pbutton; - if (needsPressed & 0x2) - frame.pubutton = pbutton; + if (needsPressed & 0x1) { + frame.pfbutton = texture->render(frame.button_w, frame.button_w, + frame.pfbutton); + if (! frame.pfbutton) + frame.pfbutton_pixel = texture->color().pixel(); + } + if (needsPressed & 0x2) { + frame.pubutton = texture->render(frame.button_w, frame.button_w, + frame.pubutton); + if (! frame.pubutton) + frame.pubutton = texture->color().pixel(); } } @@ -4229,8 +4225,6 @@ void BlackboxWindow::constrain(Corner anchor, if (dh > client.max_height) dh = client.max_height; } - assert(dw >= base_width && dh >= base_height); - if (client.width_inc > 1) { dw -= base_width; dw /= client.width_inc; diff --git a/util/epist/ChangeLog b/util/epist/ChangeLog index bf6df707..39b0e003 100644 --- a/util/epist/ChangeLog +++ b/util/epist/ChangeLog @@ -1,3 +1,12 @@ + * Fixed (hopefully) the ugly bugly that would cause (Marius) + epist to hog the keyboard on invalid keys. + + * Added stackedCyclingRaise option, to allow windows (Marius) + to raise on focus when stacked is on. + + * Small fixes, better sanity checks, much better (Marius) + error reporting on bad keys and modifiers. + 2.1.0 * Improved parser: much better error reporting for diff --git a/util/epist/config.cc b/util/epist/config.cc index cefa28cc..461778e5 100644 --- a/util/epist/config.cc +++ b/util/epist/config.cc @@ -97,6 +97,7 @@ void Config::addOption(const std::string &name, const std::string &value) } bool_options[] = { { "stackedcycling", Config::stackedCycling }, + { "stackedcyclingraise", Config::stackedCyclingRaise }, { "", NUM_BOOL_TYPES } }; diff --git a/util/epist/config.hh b/util/epist/config.hh index 2c295747..8749009d 100644 --- a/util/epist/config.hh +++ b/util/epist/config.hh @@ -36,6 +36,7 @@ public: enum BoolType { NO_BOOL_TYPE, stackedCycling, + stackedCyclingRaise, NUM_BOOL_TYPES }; diff --git a/util/epist/epist.1.in b/util/epist/epist.1.in index 65c51e0e..5e9175b2 100644 --- a/util/epist/epist.1.in +++ b/util/epist/epist.1.in @@ -5,7 +5,7 @@ epist - NetWM keybindings grabber \fBepist\fR [options] .SH DESCRIPTION \fBepist\fR is intended to provide keygrabbing for the OpenBox window manager -for the X Windows System. This allows you to control things with keypresses +for the X Window System. This allows you to control things with keypresses rather than the mouse. .SH OPTIONS .TP diff --git a/util/epist/epistrc.5.in b/util/epist/epistrc.5.in index a11013b8..06615768 100644 --- a/util/epist/epistrc.5.in +++ b/util/epist/epistrc.5.in @@ -62,18 +62,23 @@ Control-Mod1-x { .br } .SH OPTIONS -.SS stackedCycling (boolean) +.SS stackedCycling (boolean, default=off) When this option is set to True, any window cycling actions, such as nextWindow, prevWindow, nextWindowOfClass, etc., will cause the windows to focus, but they will not be raised until the modifiers are released. When the modifier is released, the focused (and now raised) window will be moved to the top of the stacking order, so if you execute nextWindow and release the modifiers multiple times, focus will cycle between two windows. -.SS chainTimeout (number) +.SS stackedCyclingRaise (boolean, default=off) +This option modifies the window raise behavior when stackedCycling is turned on. +When true, windows will be raised immediatly on focus, rather than when the +keys are released. This may be desirable if you frequently have windows that are +obscured by other windows. +.SS chainTimeout (number, default=3500) Specifies the period of time after which a started key chain will be timed out. It takes a number argument specifying the number of milliseconds to wait. It defaults to 4000. -.SS workspaceColumns (number) +.SS workspaceColumns (number, default=0, disabled) Specifies the number of columns of your workspace layout if you are using your workspaces in a 2-dimensional manner. This option must exist if one of the prevWorkspaceColumn, prevWorkspaceRow, nextWorkspaceColumn, diff --git a/util/epist/keytree.cc b/util/epist/keytree.cc index 009cb355..94b542b0 100644 --- a/util/epist/keytree.cc +++ b/util/epist/keytree.cc @@ -29,6 +29,7 @@ #include "config.hh" #include +#include using std::string; @@ -84,18 +85,26 @@ void keytree::grabDefaults(screen *scr) void keytree::ungrabDefaults(screen *scr) { + Action *act; + ChildList::const_iterator it, end = _head->children.end(); - for (it = _head->children.begin(); it != end; ++it) - if ( (*it)->action && (*it)->action->type() != Action::toggleGrabs) - scr->ungrabKey( (*it)->action->keycode(), (*it)->action->modifierMask() ); + for (it = _head->children.begin(); it != end; ++it) { + act = (*it)->action; + if (act && act->type() != Action::toggleGrabs) + scr->ungrabKey(act->keycode(), act->modifierMask()); + } } void keytree::grabChildren(keynode *node, screen *scr) { + Action *act; + ChildList::const_iterator it, end = node->children.end(); - for (it = node->children.begin(); it != end; ++it) - if ( (*it)->action ) - scr->grabKey( (*it)->action->keycode(), (*it)->action->modifierMask() ); + for (it = node->children.begin(); it != end; ++it) { + act = (*it)->action; + if (act) + scr->grabKey(act->keycode(), act->modifierMask()); + } } void keytree::ungrabChildren(keynode *node, screen *scr) @@ -178,8 +187,6 @@ const Action * keytree::getAction(const XEvent &e, unsigned int state, void keytree::addAction(Action::ActionType action, unsigned int mask, string key, string arg) { - keynode *tmp = new keynode; - if (action == Action::toggleGrabs && _current != _head) { // the toggleGrabs key can only be set up as a root key, since if // it was a chain key, we'd have to not ungrab the whole chain up @@ -187,9 +194,11 @@ void keytree::addAction(Action::ActionType action, unsigned int mask, return; } + KeySym sym = XStringToKeysym(key.c_str()); + keynode *tmp = new keynode; + tmp->action = new Action(action, - XKeysymToKeycode(_display, - XStringToKeysym(key.c_str())), + XKeysymToKeycode(_display, sym), mask, arg); tmp->parent = _current; _current->children.push_back(tmp); @@ -215,10 +224,10 @@ void keytree::setCurrentNodeProps(Action::ActionType action, unsigned int mask, { if (_current->action) delete _current->action; - + + KeySym sym = XStringToKeysym(key.c_str()); _current->action = new Action(action, - XKeysymToKeycode(_display, - XStringToKeysym(key.c_str())), + XKeysymToKeycode(_display, sym), mask, arg); } diff --git a/util/epist/parser.cc b/util/epist/parser.cc index 00be5d7e..f6ed589e 100644 --- a/util/epist/parser.cc +++ b/util/epist/parser.cc @@ -54,13 +54,29 @@ void parser::parse(string rc_file) yyin = fopen(rc_file.c_str(), "r"); - yyparse(this); + if (yyin) { + yyparse(this); + fclose(yyin); + } else { + std::cerr << "ERROR: Configuration file could not be opened/found.\n"; + } - fclose(yyin); _kt->reset(); _kt->initialize(); } +void parser::setKey(string key) +{ + KeySym sym = XStringToKeysym(key.c_str()); + + if (sym == 0) { + std::cerr << "ERROR: Invalid key (" << key << ")! This may cause odd behavior.\n"; + _add = false; + } else { + _key = key; + } +} + void parser::setAction(string act) { struct { @@ -189,14 +205,11 @@ void parser::endChain() void parser::setChainBinding() { - if (_mask != 0 && _key != "") { - if (!_add) { - cout << "Error: Bad modifier detected on chain's root key.\n"; - _add = true; - } + if (_add) _kt->setCurrentNodeProps(Action::noaction, _mask, _key, ""); - reset(); - } + + _add = true; + reset(); } void parser::reset() diff --git a/util/epist/parser.hh b/util/epist/parser.hh index b1c02a31..d106f16d 100644 --- a/util/epist/parser.hh +++ b/util/epist/parser.hh @@ -36,9 +36,6 @@ public: void parse(std::string); - void setKey(std::string key) - { _key = key; } - void setArgumentNum(std::string arg) { _arg = arg; } @@ -57,6 +54,7 @@ public: void setOption(std::string opt) { _config->addOption(opt, _arg); } + void setKey(std::string); void setAction(std::string); void addModifier(std::string); void endAction(); diff --git a/util/epist/screen.cc b/util/epist/screen.cc index 5711d551..ca029652 100644 --- a/util/epist/screen.cc +++ b/util/epist/screen.cc @@ -66,7 +66,7 @@ using std::string; screen::screen(epist *epist, int number) : _clients(epist->clientsList()), _active(epist->activeWindow()), _config(epist->getConfig()), _grabbed(true), _cycling(false), - _stacked_cycling(false) + _stacked_cycling(false), _stacked_raise(false) { _epist = epist; _xatom = _epist->xatom(); @@ -76,6 +76,8 @@ screen::screen(epist *epist, int number) _root = _info->getRootWindow(); _config->getValue(Config::stackedCycling, _stacked_cycling); + if (_stacked_cycling) + _config->getValue(Config::stackedCyclingRaise, _stacked_raise); // find a window manager supporting NETWM, waiting for it to load if we must int count = 20; // try for 20 seconds @@ -656,10 +658,11 @@ void screen::cycleWindow(unsigned int state, const bool forward, // if the window is on another desktop, we can't use XSetInputFocus, since // it doesn't imply a workspace change. - if (t->desktop() == _active_desktop || t->desktop() == 0xffffffff) - t->focus(false); // focus, but don't raise + if (_stacked_raise || (t->desktop() != _active_desktop && + t->desktop() != 0xffffffff)) + t->focus(); // raise else - t->focus(); // change workspace and focus + t->focus(false); // don't raise } else { t->focus(); diff --git a/util/epist/screen.hh b/util/epist/screen.hh index 92533d98..f0f3de07 100644 --- a/util/epist/screen.hh +++ b/util/epist/screen.hh @@ -59,6 +59,7 @@ class screen { bool _grabbed; // used for keygrab toggle function bool _cycling; // used for stacked cycling bool _stacked_cycling; + bool _stacked_raise; XWindow *findWindow(const XEvent &e) const; void updateNumDesktops(); -- 2.34.1