X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2FScreen.cc;h=2c46a836b6d2b587cd7ae5768f49b692348856ff;hb=f290e1c04c6487602452706ea075d9eccdbd17e3;hp=3d1932954fefca2765718e598d9ef38638bcd795;hpb=e148f58d0ec90f532df7c6c882e331c8bc8b7a59;p=chaz%2Fopenbox diff --git a/src/Screen.cc b/src/Screen.cc index 3d193295..2c46a836 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -49,6 +49,7 @@ #include "Window.h" #include "Workspace.h" #include "Workspacemenu.h" +#include "Util.h" #ifdef HAVE_STDLIB_H # include @@ -189,28 +190,6 @@ static const char *getFontSize(const char *pattern, int *size) { BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), openbox(ob), config(conf) { - // default values - resource.full_max = false; - resource.focus_new = false; - resource.focus_last = false; - resource.row_direction = LeftRight; - resource.col_direction = TopBottom; - resource.workspaces = 1; - resource.sloppy_focus = true; - resource.auto_raise = false; - resource.zones = 1; - resource.placement_policy = CascadePlacement; -#ifdef HAVE_STRFTIME - resource.strftime_format = bstrdup("%I:%M %p"); -#else // !have_strftime - resource.date_format = B_AmericanDate; - resource.clock24hour = false; -#endif // HAVE_STRFTIME - resource.edge_snap_threshold = 4; - resource.image_dither = true; - resource.root_command = NULL; - resource.opaque_move = false; - event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask | SubstructureRedirectMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask; @@ -265,8 +244,6 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn), image_control->installRootColormap(); root_colormap_installed = True; - image_control->setDither(resource.image_dither); - load(); // load config options from Resources LoadStyle(); @@ -613,6 +590,108 @@ BScreen::~BScreen(void) { resource.tstyle.b_pic_gc); } + +Rect BScreen::availableArea() const { + // the following code is temporary and will be taken care of by Screen in the + // future (with the NETWM 'strut') + Rect space(0, 0, size().w(), size().h()); + if (!resource.full_max) { +#ifdef SLIT + int slit_x = slit->autoHide() ? slit->hiddenOrigin().x() : slit->area().x(), + slit_y = slit->autoHide() ? slit->hiddenOrigin().y() : slit->area().y(); + int tbarh = resource.hide_toolbar ? 0 : + toolbar->getExposedHeight() + resource.border_width * 2; + bool tbartop; + switch (toolbar->placement()) { + case Toolbar::TopLeft: + case Toolbar::TopCenter: + case Toolbar::TopRight: + tbartop = true; + break; + case Toolbar::BottomLeft: + case Toolbar::BottomCenter: + case Toolbar::BottomRight: + tbartop = false; + break; + default: + ASSERT(false); // unhandled placement + } + if ((slit->direction() == Slit::Horizontal && + (slit->placement() == Slit::TopLeft || + slit->placement() == Slit::TopRight)) || + slit->placement() == Slit::TopCenter) { + // exclude top + if (tbartop && slit_y + slit->area().h() < tbarh) { + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } else { + space.setY(space.y() + (slit_y + slit->area().h() + + resource.border_width * 2)); + space.setH(space.h() - (slit_y + slit->area().h() + + resource.border_width * 2)); + if (!tbartop) + space.setH(space.h() - tbarh); + } + } else if ((slit->direction() == Slit::Vertical && + (slit->placement() == Slit::TopRight || + slit->placement() == Slit::BottomRight)) || + slit->placement() == Slit::CenterRight) { + // exclude right + space.setW(space.w() - (size().w() - slit_x)); + if (tbartop) + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } else if ((slit->direction() == Slit::Horizontal && + (slit->placement() == Slit::BottomLeft || + slit->placement() == Slit::BottomRight)) || + slit->placement() == Slit::BottomCenter) { + // exclude bottom + if (!tbartop && (size().h() - slit_y) < tbarh) { + space.setH(space.h() - tbarh); + } else { + space.setH(space.h() - (size().h() - slit_y)); + if (tbartop) { + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } + } + } else {// if ((slit->direction() == Slit::Vertical && + // (slit->placement() == Slit::TopLeft || + // slit->placement() == Slit::BottomLeft)) || + // slit->placement() == Slit::CenterLeft) + // exclude left + space.setX(slit_x + slit->area().w() + + resource.border_width * 2); + space.setW(space.w() - (slit_x + slit->area().w() + + resource.border_width * 2)); + if (tbartop) + space.setY(space.y() + tbarh); + space.setH(space.h() - tbarh); + } +#else // !SLIT + int tbarh = resource.hide_toolbar() ? 0 : + toolbar->getExposedHeight() + resource.border_width * 2; + switch (toolbar->placement()) { + case Toolbar::TopLeft: + case Toolbar::TopCenter: + case Toolbar::TopRight: + space.setY(toolbar->getExposedHeight()); + space.setH(space.h() - toolbar->getExposedHeight()); + break; + case Toolbar::BottomLeft: + case Toolbar::BottomCenter: + case Toolbar::BottomRight: + space.setH(space.h() - tbarh); + break; + default: + ASSERT(false); // unhandled placement + } +#endif // SLIT + } + return space; +} + + void BScreen::readDatabaseTexture(const char *rname, const char *rclass, BTexture *texture, unsigned long default_pixel) @@ -847,117 +926,149 @@ XFontSet BScreen::createFontSet(const char *fontname) { return fs; } + void BScreen::setSloppyFocus(bool b) { resource.sloppy_focus = b; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".focusModel" << ends; config.setValue(s.str(), (resource.sloppy_focus ? (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") : "ClickToFocus")); + s.rdbuf()->freeze(0); } + void BScreen::setAutoRaise(bool a) { resource.auto_raise = a; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".focusModel" << ends; config.setValue(s.str(), (resource.sloppy_focus ? (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus") : "ClickToFocus")); + s.rdbuf()->freeze(0); } -void BScreen::setImageDither(bool d) { + +void BScreen::setImageDither(bool d, bool reconfig) { resource.image_dither = d; - ostrstream s; + image_control->setDither(d); + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".imageDither" << ends; config.setValue(s.str(), resource.image_dither); + s.rdbuf()->freeze(0); + if (reconfig) + reconfigure(); } + void BScreen::setOpaqueMove(bool o) { resource.opaque_move = o; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends; config.setValue(s.str(), resource.opaque_move); + s.rdbuf()->freeze(0); } + void BScreen::setFullMax(bool f) { resource.full_max = f; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends; config.setValue(s.str(), resource.full_max); + s.rdbuf()->freeze(0); } + void BScreen::setFocusNew(bool f) { resource.focus_new = f; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends; config.setValue(s.str(), resource.focus_new); + s.rdbuf()->freeze(0); } + void BScreen::setFocusLast(bool f) { resource.focus_last = f; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends; config.setValue(s.str(), resource.focus_last); + s.rdbuf()->freeze(0); } + void BScreen::setWindowZones(int z) { resource.zones = z; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".windowZones" << ends; config.setValue(s.str(), resource.zones); + s.rdbuf()->freeze(0); } + void BScreen::setWorkspaceCount(int w) { resource.workspaces = w; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".workspaces" << ends; config.setValue(s.str(), resource.workspaces); + s.rdbuf()->freeze(0); } + void BScreen::setPlacementPolicy(int p) { resource.placement_policy = p; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends; const char *placement; switch (resource.placement_policy) { case CascadePlacement: placement = "CascadePlacement"; break; case BestFitPlacement: placement = "BestFitPlacement"; break; case ColSmartPlacement: placement = "ColSmartPlacement"; break; + case UnderMousePlacement: placement = "UnderMousePlacement"; break; + case ClickMousePlacement: placement = "ClickMousePlacement"; break; default: case RowSmartPlacement: placement = "RowSmartPlacement"; break; } config.setValue(s.str(), placement); + s.rdbuf()->freeze(0); } + void BScreen::setEdgeSnapThreshold(int t) { resource.edge_snap_threshold = t; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends; config.setValue(s.str(), resource.edge_snap_threshold); + s.rdbuf()->freeze(0); } + void BScreen::setRowPlacementDirection(int d) { resource.row_direction = d; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends; config.setValue(s.str(), resource.row_direction == LeftRight ? "LeftToRight" : "RightToLeft"); + s.rdbuf()->freeze(0); } + void BScreen::setColPlacementDirection(int d) { resource.col_direction = d; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends; config.setValue(s.str(), resource.col_direction == TopBottom ? "TopToBottom" : "BottomToTop"); + s.rdbuf()->freeze(0); } + void BScreen::setRootCommand(const char *cmd) { if (resource.root_command != NULL) delete [] resource.root_command; @@ -967,33 +1078,38 @@ if (resource.root_command != NULL) resource.root_command = NULL; // this doesn't save to the Resources config because it can't be changed // inside Openbox, and this way we dont add an empty command which would over- - // ride the styles commend when none has been specified + // ride the styles command when none has been specified } + + #ifdef HAVE_STRFTIME void BScreen::setStrftimeFormat(const char *f) { if (resource.strftime_format != NULL) delete [] resource.strftime_format; resource.strftime_format = bstrdup(f); - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends; config.setValue(s.str(), resource.strftime_format); + s.rdbuf()->freeze(0); } #else // !HAVE_STRFTIME void BScreen::setDateFormat(int f) { resource.date_format = f; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".dateFormat" << ends; config.setValue(s.str(), resource.date_format == B_EuropeanDate ? "European" : "American"); + s.rdbuf()->freeze(0); } void BScreen::setClock24Hour(Bool c) { resource.clock24hour = c; - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".clockFormat" << ends; config.setValue(s.str(), resource.clock24hour ? 24 : 12); + s.rdbuf()->freeze(0); } #endif // HAVE_STRFTIME @@ -1003,32 +1119,35 @@ void BScreen::setHideToolbar(bool b) { getToolbar()->unMapToolbar(); else getToolbar()->mapToolbar(); - ostrstream s; + std::ostrstream s; s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends; config.setValue(s.str(), resource.hide_toolbar ? "True" : "False"); + s.rdbuf()->freeze(0); } void BScreen::saveWorkspaceNames() { - ostrstream rc, names; - - for (int i = 0; i < resource.workspaces; i++) { - Workspace *w = getWorkspace(i); - if (w != NULL) { - names << w->getName(); - if (i < resource.workspaces-1) - names << ','; - } + std::ostrstream rc, names; + + for (int i = 0; i < resource.workspaces; i++) { + Workspace *w = getWorkspace(i); + if (w != NULL) { + names << w->getName(); + if (i < resource.workspaces-1) + names << ','; } - names << ends; + } + names << ends; - rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends; - config.setValue(rc.str(), names.str()); + rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends; + config.setValue(rc.str(), names.str()); + rc.rdbuf()->freeze(0); + names.rdbuf()->freeze(0); } void BScreen::save() { setSloppyFocus(resource.sloppy_focus); setAutoRaise(resource.auto_raise); - setImageDither(resource.image_dither); + setImageDither(resource.image_dither, false); setOpaqueMove(resource.opaque_move); setFullMax(resource.full_max); setFocusNew(resource.focus_new); @@ -1063,6 +1182,8 @@ void BScreen::load() { rclass << rscreen.str() << "HideToolbar" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.hide_toolbar = b; + else + resource.hide_toolbar = false; Toolbar *t = getToolbar(); if (t != NULL) { if (resource.hide_toolbar) @@ -1076,18 +1197,24 @@ void BScreen::load() { rclass << rscreen.str() << "FullMaximization" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.full_max = b; + else + resource.full_max = false; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "focusNewWindows" << ends; rclass << rscreen.str() << "FocusNewWindows" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.focus_new = b; + else + resource.focus_new = false; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "focusLastWindow" << ends; rclass << rscreen.str() << "FocusLastWindow" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.focus_last = b; + else + resource.focus_last = false; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "rowPlacementDirection" << ends; @@ -1095,9 +1222,10 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length())) resource.row_direction = RightLeft; - else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length())) + else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length())) resource.row_direction = LeftRight; - } + } else + resource.row_direction = LeftRight; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "colPlacementDirection" << ends; @@ -1105,15 +1233,18 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length())) resource.col_direction = BottomTop; - else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length())) + else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length())) resource.col_direction = TopBottom; - } + } else + resource.col_direction = TopBottom; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "workspaces" << ends; rclass << rscreen.str() << "Workspaces" << ends; if (config.getValue(rname.str(), rclass.str(), l)) resource.workspaces = l; + else + resource.workspaces = 1; removeWorkspaceNames(); rname.seekp(0); rclass.seekp(0); @@ -1143,10 +1274,13 @@ void BScreen::load() { s.length())) { resource.sloppy_focus = true; resource.auto_raise = true; - } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) { + } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) { resource.sloppy_focus = true; resource.auto_raise = false; } + } else { + resource.sloppy_focus = true; + resource.auto_raise = false; } rname.seekp(0); rclass.seekp(0); @@ -1154,6 +1288,8 @@ void BScreen::load() { rclass << rscreen.str() << "WindowZones" << ends; if (config.getValue(rname.str(), rclass.str(), l)) resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1; + else + resource.zones = 4; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "windowPlacement" << ends; @@ -1165,16 +1301,27 @@ void BScreen::load() { resource.placement_policy = ColSmartPlacement; else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length())) resource.placement_policy = BestFitPlacement; - else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length())) + else if (0 == strncasecmp(s.c_str(), "UnderMousePlacement", s.length())) + resource.placement_policy = UnderMousePlacement; + else if (0 == strncasecmp(s.c_str(), "ClickMousePlacement", s.length())) + resource.placement_policy = ClickMousePlacement; + else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length())) resource.placement_policy = CascadePlacement; - } + } else + resource.placement_policy = CascadePlacement; #ifdef HAVE_STRFTIME rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "strftimeFormat" << ends; rclass << rscreen.str() << "StrftimeFormat" << ends; + + if (resource.strftime_format != NULL) + delete [] resource.strftime_format; + if (config.getValue(rname.str(), rclass.str(), s)) resource.strftime_format = bstrdup(s.c_str()); + else + resource.strftime_format = bstrdup("%I:%M %p"); #else // !HAVE_STRFTIME rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "dateFormat" << ends; @@ -1182,9 +1329,10 @@ void BScreen::load() { if (config.getValue(rname.str(), rclass.str(), s)) { if (strncasecmp(s.c_str(), "European", s.length())) resource.date_format = B_EuropeanDate; - else if (strncasecmp(s.c_str(), "American", s.length())) + else //if (strncasecmp(s.c_str(), "American", s.length())) resource.date_format = B_AmericanDate; - } + } else + resource.date_format = B_AmericanDate; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "clockFormat" << ends; @@ -1194,6 +1342,8 @@ void BScreen::load() { resource.clock24hour = true; else if (clock == 12) resource.clock24hour = false; + } else + resource.clock24hour = false; #endif // HAVE_STRFTIME rname.seekp(0); rclass.seekp(0); @@ -1201,24 +1351,40 @@ void BScreen::load() { rclass << rscreen.str() << "EdgeSnapThreshold" << ends; if (config.getValue(rname.str(), rclass.str(), l)) resource.edge_snap_threshold = l; + else + resource.edge_snap_threshold = 4; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "imageDither" << ends; rclass << rscreen.str() << "ImageDither" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.image_dither = b; + else + resource.image_dither = true; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "rootCommand" << ends; rclass << rscreen.str() << "RootCommand" << ends; + + if (resource.root_command != NULL) + delete [] resource.root_command; + if (config.getValue(rname.str(), rclass.str(), s)) resource.root_command = bstrdup(s.c_str()); + else + resource.root_command = NULL; rname.seekp(0); rclass.seekp(0); rname << rscreen.str() << "opaqueMove" << ends; rclass << rscreen.str() << "OpaqueMove" << ends; if (config.getValue(rname.str(), rclass.str(), b)) resource.opaque_move = b; + else + resource.opaque_move = false; + + rscreen.rdbuf()->freeze(0); + rname.rdbuf()->freeze(0); + rclass.rdbuf()->freeze(0); } void BScreen::reconfigure(void) { @@ -1402,8 +1568,13 @@ void BScreen::removeWorkspaceNames(void) { void BScreen::LoadStyle(void) { Resource &conf = resource.styleconfig; - conf.setFile(openbox.getStyleFilename()); - if (!conf.load()) { + const char *sfile = openbox.getStyleFilename(); + bool loaded = false; + if (sfile != NULL) { + conf.setFile(sfile); + loaded = conf.load(); + } + if (!loaded) { conf.setFile(DEFAULTSTYLE); if (!conf.load()) { fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail, @@ -2160,7 +2331,7 @@ void BScreen::InitMenu(void) { rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"), BScreen::Exit); } else { - openbox.saveMenuFilename(openbox.getMenuFilename()); + openbox.setMenuFilename(openbox.getMenuFilename()); } } @@ -2361,7 +2532,7 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { if (! feof(submenufile)) { if (! parseMenuFile(submenufile, menu)) - openbox.saveMenuFilename(newfile); + openbox.setMenuFilename(newfile); fclose(submenufile); } @@ -2520,7 +2691,7 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) { rootmenuList->insert(stylesmenu); } - openbox.saveMenuFilename(stylesdir); + openbox.setMenuFilename(stylesdir); } else { fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNotDir,