From: Dana Jansens Date: Sat, 11 Jan 2003 20:37:50 +0000 (+0000) Subject: display window titles using utf if appropriate, and in the toolbar X-Git-Tag: openbox-2_3_0^2~10 X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=30ceaa3d8168f3b7ba5fbf28b74be7ec9284eb00;p=dana%2Fopenbox.git display window titles using utf if appropriate, and in the toolbar --- diff --git a/src/Basemenu.cc b/src/Basemenu.cc index 01ca387b..3f3db62e 100644 --- a/src/Basemenu.cc +++ b/src/Basemenu.cc @@ -257,7 +257,8 @@ void Basemenu::update(void) { menu.title_h = style->t_font->height() + menu.bevel_w * 2; if (title_vis) { - menu.item_w = screen->getMenuStyle()->t_font->measureString(menu.label) + + menu.item_w = screen->getMenuStyle()->t_font->measureString(menu.label, + false) + menu.bevel_w * 2; } else { menu.item_w = 1; @@ -266,7 +267,7 @@ void Basemenu::update(void) { unsigned int ii = 0; MenuItems::iterator it = menuitems.begin(), end = menuitems.end(); for (; it != end; ++it) { - ii = screen->getMenuStyle()->f_font->measureString((*it)->l) + + ii = screen->getMenuStyle()->f_font->measureString((*it)->l, false) + (menu.bevel_w * 2) + (menu.item_h * 2); menu.item_w = ((menu.item_w < ii) ? ii : menu.item_w); @@ -436,7 +437,7 @@ void Basemenu::redrawTitle(void) { unsigned int l; const MenuStyle* const style = screen->getMenuStyle(); - l = style->t_font->measureString(text) + menu.bevel_w * 2; + l = style->t_font->measureString(text, false) + menu.bevel_w * 2; switch (screen->getMenuStyle()->t_justify) { case RightJustify: @@ -454,7 +455,7 @@ void Basemenu::redrawTitle(void) { XClearWindow(display, menu.title); style->t_font->drawString(menu.title, dx, menu.bevel_w, - style->t_text, text); + style->t_text, text, false); } void Basemenu::drawSubmenu(int index) { @@ -541,7 +542,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear, text_h = 0; if (text) { - text_w = screen->getMenuStyle()->f_font->measureString(text); + text_w = screen->getMenuStyle()->f_font->measureString(text, false); text_y = item_y + menu.bevel_w / 2; switch(screen->getMenuStyle()->f_justify) { @@ -677,7 +678,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear, (highlight ? style->h_text : (item->isEnabled() ? style->f_text : style->d_text)), - text); + text, false); } if (dosel && item->submenu()) { diff --git a/src/Font.cc b/src/Font.cc index 149e75fa..773dc279 100644 --- a/src/Font.cc +++ b/src/Font.cc @@ -253,7 +253,7 @@ bool BFont::parseXlfd(const string &xlfd) { void BFont::drawString(Drawable d, int x, int y, const BColor &color, - const string &string) const { + const string &string, bool utf) const { assert(_valid); #ifdef XFT @@ -278,15 +278,18 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color, c.pixel = WhitePixel(_display, _screen->getScreenNumber()); } -#ifdef XFT_UTF8 - XftDrawStringUtf8( -#else - XftDrawString8( -#endif - draw, &c, _xftfont, x + _offset, - _xftfont->ascent + y + _offset, - (XftChar8 *) string.c_str(), - string.size()); +//#ifdef XFT_UTF8 + if (utf) + XftDrawStringUtf8(draw, &c, _xftfont, x + _offset, + _xftfont->ascent + y + _offset, + (XftChar8 *) string.c_str(), + string.size()); + else +//#endif + XftDrawString8(draw, &c, _xftfont, x + _offset, + _xftfont->ascent + y + _offset, + (XftChar8 *) string.c_str(), + string.size()); } XftColor c; @@ -296,13 +299,14 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color, c.pixel = color.pixel(); c.color.alpha = 0xff | 0xff << 8; // no transparency in BColor yet -#ifdef XFT_UTF8 - XftDrawStringUtf8( -#else - XftDrawString8( -#endif - draw, &c, _xftfont, x, _xftfont->ascent + y, - (XftChar8 *) string.c_str(), string.size()); +//#ifdef XFT_UTF8 + if (utf) + XftDrawStringUtf8(draw, &c, _xftfont, x, _xftfont->ascent + y, + (XftChar8 *) string.c_str(), string.size()); + else +//#endif + XftDrawString8(draw, &c, _xftfont, x, _xftfont->ascent + y, + (XftChar8 *) string.c_str(), string.size()); XftDrawDestroy(draw); return; @@ -322,20 +326,21 @@ void BFont::drawString(Drawable d, int x, int y, const BColor &color, } -unsigned int BFont::measureString(const string &string) const { +unsigned int BFont::measureString(const string &string, bool utf) const { assert(_valid); #ifdef XFT if (_xftfont) { XGlyphInfo info; -#ifdef XFT_UTF8 - XftTextExtentsUtf8( -#else - XftTextExtents8( -#endif - _display, _xftfont, (XftChar8 *) string.c_str(), - string.size(), &info); +//#ifdef XFT_UTF8 + if (utf) + XftTextExtentsUtf8(_display, _xftfont, (XftChar8 *) string.c_str(), + string.size(), &info); + else +//#endif + XftTextExtents8(_display, _xftfont, (XftChar8 *) string.c_str(), + string.size(), &info); return info.xOff + (_shadow ? std::abs(_offset) : 0); } diff --git a/src/Font.hh b/src/Font.hh index 6f6431ef..9a84357a 100644 --- a/src/Font.hh +++ b/src/Font.hh @@ -115,10 +115,10 @@ public: unsigned int height(void) const; unsigned int maxCharWidth(void) const; - unsigned int measureString(const std::string &string) const; + unsigned int measureString(const std::string &string, bool utf) const; void drawString(Drawable d, int x, int y, const BColor &color, - const std::string &string) const; + const std::string &string, bool utf) const; }; #endif // __Font_hh diff --git a/src/Screen.cc b/src/Screen.cc index c4534904..18ecd5a6 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -181,7 +181,8 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) { const char *s = i18n(ScreenSet, ScreenPositionLength, "0: 0000 x 0: 0000"); - geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2; + geom_w = resource.wstyle.font->measureString(s, false) + + resource.bevel_width * 2; geom_h = resource.wstyle.font->height() + resource.bevel_width * 2; XSetWindowAttributes attrib; @@ -939,7 +940,8 @@ void BScreen::reconfigure(void) { const char *s = i18n(ScreenSet, ScreenPositionLength, "0: 0000 x 0: 0000"); - geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2; + geom_w = resource.wstyle.font->measureString(s, false) + + resource.bevel_width * 2; geom_h = resource.wstyle.font->height() + resource.bevel_width * 2; BTexture* texture = &(resource.wstyle.l_focus); @@ -2433,7 +2435,7 @@ void BScreen::showPosition(int x, int y) { resource.wstyle.font->drawString(geom_window, resource.bevel_width, resource.bevel_width, resource.wstyle.l_text_focus, - label); + label, false); } @@ -2458,7 +2460,7 @@ void BScreen::showGeometry(unsigned int gx, unsigned int gy) { resource.wstyle.font->drawString(geom_window, resource.bevel_width, resource.bevel_width, resource.wstyle.l_text_focus, - label); + label, false); } diff --git a/src/Screen.hh b/src/Screen.hh index ca19b2cd..01a08b4c 100644 --- a/src/Screen.hh +++ b/src/Screen.hh @@ -83,7 +83,8 @@ struct WindowStyle { TextJustify justify; void doJustify(const std::string &text, int &start_pos, - unsigned int max_length, unsigned int modifier) const; + unsigned int max_length, unsigned int modifier, + bool utf) const; }; struct ToolbarStyle { @@ -99,7 +100,8 @@ struct ToolbarStyle { TextJustify justify; void doJustify(const std::string &text, int &start_pos, - unsigned int max_length, unsigned int modifier) const; + unsigned int max_length, unsigned int modifier, + bool utf) const; }; struct MenuStyle { diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 14d347ef..6d3d3705 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -363,7 +363,7 @@ void Toolbar::reconfigure(void) { // find the length of the rendered string and add room for two extra // characters to it. This allows for variable width output of the fonts BFont *font = screen->getToolbarStyle()->font; - frame.clock_w = font->measureString(t) + font->maxCharWidth() * 2; + frame.clock_w = font->measureString(t, false) + font->maxCharWidth() * 2; } } #else // !HAVE_STRFTIME @@ -377,7 +377,8 @@ void Toolbar::reconfigure(void) { for (unsigned int i = 0; i < screen->getWorkspaceCount(); i++) { const string& workspace_name = screen->getWorkspace(i)->getName(); - width = screen->getToolbarStyle()->font->measureString(workspace_name); + width = screen->getToolbarStyle()->font->measureString(workspace_name, + false); if (width > frame.workspace_label_w) frame.workspace_label_w = width; } @@ -580,13 +581,13 @@ void Toolbar::checkClock(bool redraw, bool date) { ToolbarStyle *style = screen->getToolbarStyle(); int pos = frame.bevel_w * 2; // this is modified by doJustify() - style->doJustify(t, pos, frame.clock_w, frame.bevel_w * 4); + style->doJustify(t, pos, frame.clock_w, frame.bevel_w * 4, false); #ifdef XFT XClearWindow(display, frame.clock); #endif // XFT - style->font->drawString(frame.clock, pos, 1, style->c_text, t); + style->font->drawString(frame.clock, pos, 1, style->c_text, t, false); } } @@ -608,11 +609,13 @@ void Toolbar::redrawWindowLabel(bool redraw) { if (foc->getScreen() != screen) return; const char *title = foc->getTitle(); + bool utf = foc->getTitleUtf(); ToolbarStyle *style = screen->getToolbarStyle(); int pos = frame.bevel_w * 2; // modified by doJustify() - style->doJustify(title, pos, frame.window_label_w, frame.bevel_w * 4); - style->font->drawString(frame.window_label, pos, 1, style->w_text, title); + style->doJustify(title, pos, frame.window_label_w, frame.bevel_w * 4, utf); + style->font->drawString(frame.window_label, pos, 1, style->w_text, title, + utf); } @@ -630,8 +633,9 @@ void Toolbar::redrawWorkspaceLabel(bool redraw) { int pos = frame.bevel_w * 2; style->doJustify(name.c_str(), pos, frame.workspace_label_w, - frame.bevel_w * 4); - style->font->drawString(frame.workspace_label, pos, 1, style->l_text, name); + frame.bevel_w * 4, false); + style->font->drawString(frame.workspace_label, pos, 1, style->l_text, name, + false); } @@ -1012,14 +1016,15 @@ void Toolbar::keyPressEvent(const XKeyEvent *ke) { XClearWindow(display, frame.workspace_label); unsigned int tw, x; - tw = screen->getToolbarStyle()->font->measureString(new_workspace_name); + tw = screen->getToolbarStyle()->font->measureString(new_workspace_name, + false); x = (frame.workspace_label_w - tw) / 2; if (x < frame.bevel_w) x = frame.bevel_w; ToolbarStyle *style = screen->getToolbarStyle(); style->font->drawString(frame.workspace_label, x, 1, style->l_text, - new_workspace_name); + new_workspace_name, false); BPen pen(style->l_text); XDrawRectangle(display, frame.workspace_label, pen.gc(), x + tw, 0, 1, frame.label_h - 1); @@ -1212,12 +1217,13 @@ void Toolbarmenu::Placementmenu::itemSelected(int button, unsigned int index) { void ToolbarStyle::doJustify(const std::string &text, int &start_pos, unsigned int max_length, - unsigned int modifier) const { + unsigned int modifier, bool utf) const { size_t text_len = text.size(); unsigned int length; do { - length = font->measureString(string(text, 0, text_len)) + modifier; + length = font->measureString(string(text, 0, text_len), utf) + + modifier; } while (length > max_length && text_len-- > 0); switch (justify) { diff --git a/src/Window.cc b/src/Window.cc index 7b971eda..50431428 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -1158,18 +1158,21 @@ void BlackboxWindow::getWMName(void) { XAtom::utf8, client.title) && !client.title.empty()) { xatom->eraseValue(client.window, XAtom::net_wm_visible_name); + client.title_utf = true; return; } //fall through to using WM_NAME if (xatom->getValue(client.window, XAtom::wm_name, XAtom::ansi, client.title) && !client.title.empty()) { xatom->eraseValue(client.window, XAtom::net_wm_visible_name); + client.title_utf = false; return; } // fall back to an internal default client.title = i18n(WindowSet, WindowUnnamed, "Unnamed"); xatom->setValue(client.window, XAtom::net_wm_visible_name, XAtom::utf8, client.title); + client.title_utf = false; #ifdef DEBUG_WITH_ID // the 16 is the 8 chars of the debug text plus the number @@ -1186,6 +1189,7 @@ void BlackboxWindow::getWMIconName(void) { XAtom::utf8, client.icon_title) && !client.icon_title.empty()) { xatom->eraseValue(client.window, XAtom::net_wm_visible_icon_name); + client.icon_title_utf = true; return; } //fall through to using WM_ICON_NAME @@ -1193,12 +1197,14 @@ void BlackboxWindow::getWMIconName(void) { client.icon_title) && !client.icon_title.empty()) { xatom->eraseValue(client.window, XAtom::net_wm_visible_icon_name); + client.icon_title_utf = false; return; } // fall back to using the main name client.icon_title = client.title; xatom->setValue(client.window, XAtom::net_wm_visible_icon_name, XAtom::utf8, client.icon_title); + client.icon_title_utf = client.title_utf; } @@ -2613,11 +2619,12 @@ void BlackboxWindow::redrawLabel(void) const { WindowStyle *style = screen->getWindowStyle(); int pos = frame.bevel_w * 2; - style->doJustify(client.title.c_str(), pos, frame.label_w, frame.bevel_w * 4); + style->doJustify(client.title.c_str(), pos, frame.label_w, frame.bevel_w * 4, + client.title_utf); style->font->drawString(frame.label, pos, 1, (flags.focused ? style->l_text_focus : style->l_text_unfocus), - client.title); + client.title, client.title_utf); } @@ -4292,12 +4299,12 @@ void BlackboxWindow::constrain(Corner anchor, void WindowStyle::doJustify(const std::string &text, int &start_pos, unsigned int max_length, - unsigned int modifier) const { + unsigned int modifier, bool utf) const { size_t text_len = text.size(); unsigned int length; do { - length = font->measureString(string(text, 0, text_len)) + modifier; + length = font->measureString(string(text, 0, text_len), utf) + modifier; } while (length > max_length && text_len-- > 0); switch (justify) { diff --git a/src/Window.hh b/src/Window.hh index b923c4bf..126d9cbb 100644 --- a/src/Window.hh +++ b/src/Window.hh @@ -167,6 +167,7 @@ private: BlackboxWindowList transientList; // which windows are our transients? std::string title, icon_title; + bool title_utf, icon_title_utf; Rect rect; Strut strut; @@ -355,10 +356,11 @@ public: inline Windowmenu * getWindowmenu(void) const { return windowmenu; } - inline const char *getTitle(void) const - { return client.title.c_str(); } + inline const char *getTitle(void) const { return client.title.c_str(); } + inline bool getTitleUtf(void) const { return client.title_utf; } inline const char *getIconTitle(void) const - { return client.icon_title.c_str(); } + { return client.icon_title.c_str(); } + inline bool getIconTitleUtf(void) const { return client.icon_title_utf; } inline unsigned int getWorkspaceNumber(void) const { return blackbox_attrib.workspace; }