-void BScreen::load_rc(void) {
- std::string s;
- bool b;
-
- if (! config->getValue(screenstr + "fullMaximization", resource.full_max))
- resource.full_max = false;
-
- if (! config->getValue(screenstr + "focusNewWindows", resource.focus_new))
- resource.focus_new = false;
-
- if (! config->getValue(screenstr + "focusLastWindow", resource.focus_last))
- resource.focus_last = false;
-
- if (! config->getValue(screenstr + "workspaces", resource.workspaces))
- resource.workspaces = 1;
-
- if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
- resource.opaque_move = false;
-
- if (! config->getValue(screenstr + "antialiasFonts", resource.aa_fonts))
- resource.aa_fonts = true;
-
- if (! resource.aa_fonts ||
- ! config->getValue(screenstr + "dropShadowFonts", resource.shadow_fonts))
- resource.shadow_fonts = false;
-
- if (! config->getValue(screenstr + "resizeZones", resource.resize_zones) ||
- (resource.resize_zones != 1 && resource.resize_zones != 2 &&
- resource.resize_zones != 4))
- resource.resize_zones = 4;
-
- resource.snap_to_windows = WindowResistance;
- if (config->getValue(screenstr + "windowToWindowSnap", s)) {
- if (s == "NoSnap")
- resource.snap_to_windows = WindowNoSnap;
- else if (s == "Snap")
- resource.snap_to_windows = WindowSnap;
- }
-
- resource.snap_to_edges = WindowResistance;
- if (config->getValue(screenstr + "windowToEdgeSnap", s)) {
- if (s == "NoSnap")
- resource.snap_to_edges = WindowNoSnap;
- else if (s == "Snap")
- resource.snap_to_edges = WindowSnap;
- }
-
- if (! config->getValue(screenstr + "windowCornerSnap",
- resource.window_corner_snap))
- resource.window_corner_snap = true;
-
- if (! config->getValue(screenstr + "imageDither", b))
- b = true;
- image_control->setDither(b);
-
- if (! config->getValue(screenstr + "edgeSnapOffset",
- resource.snap_offset))
- resource.snap_offset = 0;
- if (resource.snap_offset > 50) // sanity check, setting this huge would
- resource.snap_offset = 50; // seriously suck.
-
- if (! config->getValue(screenstr + "edgeSnapThreshold",
- resource.snap_threshold))
- resource.snap_threshold = 4;
-
- if (! config->getValue(screenstr + "resistanceSize",
- resource.resistance_size))
- resource.resistance_size = 18;
-
- if (config->getValue(screenstr + "rowPlacementDirection", s) &&
- s == "RightToLeft")
- resource.row_direction = RightLeft;
- else
- resource.row_direction = LeftRight;
-
- if (config->getValue(screenstr + "colPlacementDirection", s) &&
- s == "BottomToTop")
- resource.col_direction = BottomTop;
- else
- resource.col_direction = TopBottom;
-
- if (config->getValue(screenstr + "workspaceNames", s)) {
- otk::OBProperty::StringVect workspaceNames;
-
- string::const_iterator it = s.begin(), end = s.end();
- while(1) {
- string::const_iterator tmp = it; // current string.begin()
- it = std::find(tmp, end, ','); // look for comma between tmp and end
- workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
- if (it == end)
- break;
- ++it;
- }
-
- xatom->set(getRootWindow(), otk::OBProperty::net_desktop_names,
- otk::OBProperty::utf8, workspaceNames);
- }
-
- resource.sloppy_focus = true;
- resource.auto_raise = false;
- resource.click_raise = false;
- if (config->getValue(screenstr + "focusModel", s)) {
- if (s.find("ClickToFocus") != string::npos) {
- resource.sloppy_focus = false;
- } else {
- // must be sloppy
- if (s.find("AutoRaise") != string::npos)
- resource.auto_raise = true;
- if (s.find("ClickRaise") != string::npos)
- resource.click_raise = true;
- }
- }
-
- if (config->getValue(screenstr + "windowPlacement", s)) {
- if (s == "CascadePlacement")
- resource.placement_policy = CascadePlacement;
- else if (s == "UnderMousePlacement")
- resource.placement_policy = UnderMousePlacement;
- else if (s == "ClickMousePlacement")
- resource.placement_policy = ClickMousePlacement;
- else if (s == "ColSmartPlacement")
- resource.placement_policy = ColSmartPlacement;
- else //if (s == "RowSmartPlacement")
- resource.placement_policy = RowSmartPlacement;
- } else
- resource.placement_policy = RowSmartPlacement;
-
- if (! config->getValue(screenstr + "strftimeFormat",
- resource.strftime_format))
- resource.strftime_format = "%I:%M %p";
-
- if (! config->getValue(screenstr + "placementIgnoreShaded",
- resource.ignore_shaded))
- resource.ignore_shaded = true;
-
- if (! config->getValue(screenstr + "placementIgnoreMaximized",
- resource.ignore_maximized))
- resource.ignore_maximized = true;
-
- if (! config->getValue(screenstr + "disableBindingsWithScrollLock",
- resource.allow_scroll_lock))
- resource.allow_scroll_lock = false;
-
- if (! config->getValue(screenstr + "workspaceWarping",
- resource.workspace_warping))
- resource.workspace_warping = false;
-
- resource.root_scroll = NormalScroll;
- if (config->getValue(screenstr + "rootScrollDirection", s)) {
- if (s == "None")
- resource.root_scroll = NoScroll;
- else if (s == "Reverse")
- resource.root_scroll = ReverseScroll;
- }
-}
-
-
-void BScreen::changeWorkspaceCount(unsigned int new_count) {
- assert(new_count > 0);
-
- if (new_count < workspacesList.size()) {
- // shrink
- for (unsigned int i = workspacesList.size(); i > new_count; --i)
- removeLastWorkspace();
- // removeLast already sets the current workspace to the
- // last available one.
- } else if (new_count > workspacesList.size()) {
- // grow
- for(unsigned int i = workspacesList.size(); i < new_count; ++i)
- addWorkspace();
- }
-}
-
-
-void BScreen::reconfigure(void) {
- // don't reconfigure while saving the initial rc file, it's a waste and it
- // breaks somethings (workspace names)
- if (blackbox->state() == Openbox::State_Starting) return;
-
- load_rc();
- LoadStyle();
-
- // we need to do this explicitly, because just loading this value from the rc
- // does nothing
- changeWorkspaceCount(resource.workspaces);
-
- XGCValues gcv;
- gcv.foreground = WhitePixel(otk::OBDisplay::display,
- getScreenNumber());
- gcv.function = GXinvert;
- gcv.subwindow_mode = IncludeInferiors;
- XChangeGC(otk::OBDisplay::display, opGC,
- GCForeground | GCFunction | GCSubwindowMode, &gcv);
-
- const char *s = "0: 0000 x 0: 0000";
-
- geom_w = resource.wstyle.font->measureString(s) + resource.bevel_width * 2;
- geom_h = resource.wstyle.font->height() + resource.bevel_width * 2;
-
- otk::BTexture* texture = &(resource.wstyle.l_focus);
- geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
- if (geom_pixmap == ParentRelative) {
- texture = &(resource.wstyle.t_focus);
- geom_pixmap = texture->render(geom_w, geom_h, geom_pixmap);
- }
- if (! geom_pixmap)
- XSetWindowBackground(otk::OBDisplay::display, geom_window,
- texture->color().pixel());
- else
- XSetWindowBackgroundPixmap(otk::OBDisplay::display,
- geom_window, geom_pixmap);
-
- XSetWindowBorderWidth(otk::OBDisplay::display, geom_window,
- resource.border_width);
- XSetWindowBorder(otk::OBDisplay::display, geom_window,
- resource.border_color.pixel());
-
- typedef std::vector<int> SubList;
- SubList remember_subs;
-
- raiseWindows(0, 0);
-
- std::for_each(workspacesList.begin(), workspacesList.end(),
- std::mem_fun(&Workspace::reconfigure));
-
- BlackboxWindowList::iterator iit = iconList.begin();
- for (; iit != iconList.end(); ++iit) {
- BlackboxWindow *bw = *iit;
- if (bw->validateClient())
- bw->reconfigure();
- }
-
- otk::BImageControl::timeout(image_control);
-}
-
-
-void BScreen::LoadStyle(void) {
- Configuration style(False);
-
- const char *sfile = blackbox->getStyleFilename();
- if (sfile != NULL) {
- style.setFile(sfile);
- if (! style.load()) {
- style.setFile(DEFAULTSTYLE);
- if (! style.load())
- style.create(); // hardcoded default values will be used.
- }
- }
-
- // merge in the rc file
- style.merge(config->file(), True);
-
- string s;
-
- // load fonts/fontsets
- if (resource.wstyle.font)
- delete resource.wstyle.font;
-
- resource.wstyle.font = readDatabaseFont("window.", style);
-
- // load window config
- resource.wstyle.t_focus =
- readDatabaseTexture("window.title.focus", "white", style);
- resource.wstyle.t_unfocus =
- readDatabaseTexture("window.title.unfocus", "black", style);
- resource.wstyle.l_focus =
- readDatabaseTexture("window.label.focus", "white", style);
- resource.wstyle.l_unfocus =
- readDatabaseTexture("window.label.unfocus", "black", style);
- resource.wstyle.h_focus =
- readDatabaseTexture("window.handle.focus", "white", style);
- resource.wstyle.h_unfocus =
- readDatabaseTexture("window.handle.unfocus", "black", style);
- resource.wstyle.g_focus =
- readDatabaseTexture("window.grip.focus", "white", style);
- resource.wstyle.g_unfocus =
- readDatabaseTexture("window.grip.unfocus", "black", style);
- resource.wstyle.b_focus =
- readDatabaseTexture("window.button.focus", "white", style);
- resource.wstyle.b_unfocus =
- readDatabaseTexture("window.button.unfocus", "black", style);
- resource.wstyle.b_pressed =
- readDatabaseTexture("window.button.pressed", "black", style);
-
- //if neither of these can be found, we will use the previous resource
- resource.wstyle.b_pressed_focus =
- readDatabaseTexture("window.button.pressed.focus", "black", style, true);
- resource.wstyle.b_pressed_unfocus =
- readDatabaseTexture("window.button.pressed.unfocus", "black", style, true);
-
- if (resource.wstyle.close_button.mask != None)
- XFreePixmap(otk::OBDisplay::display, resource.wstyle.close_button.mask);
- if (resource.wstyle.max_button.mask != None)
- XFreePixmap(otk::OBDisplay::display, resource.wstyle.max_button.mask);
- if (resource.wstyle.icon_button.mask != None)
- XFreePixmap(otk::OBDisplay::display, resource.wstyle.icon_button.mask);
- if (resource.wstyle.stick_button.mask != None)
- XFreePixmap(otk::OBDisplay::display, resource.wstyle.stick_button.mask);
-
- resource.wstyle.close_button.mask = resource.wstyle.max_button.mask =
- resource.wstyle.icon_button.mask =
- resource.wstyle.icon_button.mask = None;
-
- readDatabaseMask("window.button.close.mask", resource.wstyle.close_button,
- style);
- readDatabaseMask("window.button.max.mask", resource.wstyle.max_button,
- style);
- readDatabaseMask("window.button.icon.mask", resource.wstyle.icon_button,
- style);
- readDatabaseMask("window.button.stick.mask", resource.wstyle.stick_button,
- style);
-
- // we create the window.frame texture by hand because it exists only to
- // make the code cleaner and is not actually used for display
- otk::BColor color = readDatabaseColor("window.frame.focusColor", "white",
- style);
- resource.wstyle.f_focus = otk::BTexture("solid flat", getScreenNumber(),
- image_control);
- resource.wstyle.f_focus.setColor(color);
-
- color = readDatabaseColor("window.frame.unfocusColor", "white", style);
- resource.wstyle.f_unfocus = otk::BTexture("solid flat", getScreenNumber(),
- image_control);
- resource.wstyle.f_unfocus.setColor(color);
-
- resource.wstyle.l_text_focus =
- readDatabaseColor("window.label.focus.textColor", "black", style);
- resource.wstyle.l_text_unfocus =
- readDatabaseColor("window.label.unfocus.textColor", "white", style);
- resource.wstyle.b_pic_focus =
- readDatabaseColor("window.button.focus.picColor", "black", style);
- resource.wstyle.b_pic_unfocus =
- readDatabaseColor("window.button.unfocus.picColor", "white", style);
-
- resource.wstyle.justify = LeftJustify;
- if (style.getValue("window.justify", s)) {
- if (s == "right" || s == "Right")
- resource.wstyle.justify = RightJustify;
- else if (s == "center" || s == "Center")
- resource.wstyle.justify = CenterJustify;
- }
-
- // sanity checks
- if (resource.wstyle.t_focus.texture() == otk::BTexture::Parent_Relative)
- resource.wstyle.t_focus = resource.wstyle.f_focus;
- if (resource.wstyle.t_unfocus.texture() == otk::BTexture::Parent_Relative)
- resource.wstyle.t_unfocus = resource.wstyle.f_unfocus;
- if (resource.wstyle.h_focus.texture() == otk::BTexture::Parent_Relative)
- resource.wstyle.h_focus = resource.wstyle.f_focus;
- if (resource.wstyle.h_unfocus.texture() == otk::BTexture::Parent_Relative)
- resource.wstyle.h_unfocus = resource.wstyle.f_unfocus;
-
- resource.border_color =
- readDatabaseColor("borderColor", "black", style);
-
- // load bevel, border and handle widths
- if (! style.getValue("handleWidth", resource.handle_width) ||
- resource.handle_width > (getWidth() / 2) || resource.handle_width == 0)
- resource.handle_width = 6;
-
- if (! style.getValue("borderWidth", resource.border_width))
- resource.border_width = 1;
-
- if (! style.getValue("bevelWidth", resource.bevel_width) ||
- resource.bevel_width > (getWidth() / 2) || resource.bevel_width == 0)
- resource.bevel_width = 3;
-
- if (! style.getValue("frameWidth", resource.frame_width) ||
- resource.frame_width > (getWidth() / 2))
- resource.frame_width = resource.bevel_width;
-
- if (style.getValue("rootCommand", s))
- bexec(s, displayString());
-}
-
-
-void BScreen::addIcon(BlackboxWindow *w) {
- if (! w) return;
-
- w->setWorkspace(BSENTINEL);
- w->setWindowNumber(iconList.size());
-
- iconList.push_back(w);
-}
-
-
-void BScreen::removeIcon(BlackboxWindow *w) {
- if (! w) return;
-
- iconList.remove(w);
-
- BlackboxWindowList::iterator it = iconList.begin(),
- end = iconList.end();
- for (int i = 0; it != end; ++it)
- (*it)->setWindowNumber(i++);
-}
-
-
-BlackboxWindow *BScreen::getIcon(unsigned int index) {
- if (index < iconList.size()) {
- BlackboxWindowList::iterator it = iconList.begin();
- while (index-- > 0) // increment to index
- ++it;
- return *it;
- }
-
- return (BlackboxWindow *) 0;
-}
-
-
-unsigned int BScreen::addWorkspace(void) {
- Workspace *wkspc = new Workspace(this, workspacesList.size());
- workspacesList.push_back(wkspc);
- saveWorkspaces(getWorkspaceCount());
- saveWorkspaceNames();
-
- return workspacesList.size();
-}
-
-
-unsigned int BScreen::removeLastWorkspace(void) {
- if (workspacesList.size() == 1)
- return 1;
-
- Workspace *wkspc = workspacesList.back();
-
- if (current_workspace->getID() == wkspc->getID())
- changeWorkspaceID(current_workspace->getID() - 1);
-
- wkspc->removeAll();
-
- workspacesList.pop_back();
- delete wkspc;
-
- saveWorkspaces(getWorkspaceCount());
- saveWorkspaceNames();
-
- updateNetizenWorkspaceCount();
-
- return workspacesList.size();
-}
-
-
-void BScreen::changeWorkspaceID(unsigned int id) {
- if (! current_workspace || id == current_workspace->getID()) return;
-
- BlackboxWindow *focused = blackbox->getFocusedWindow();
- if (focused && focused->getScreen() == this) {
- assert(focused->isStuck() ||
- focused->getWorkspaceNumber() == current_workspace->getID());
-
- current_workspace->setLastFocusedWindow(focused);
- } else {
- // if no window had focus, no need to store a last focus
- current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
- }
-
- // when we switch workspaces, unfocus whatever was focused if it is going
- // to be unmapped
- if (focused && ! focused->isStuck())
- blackbox->setFocusedWindow((BlackboxWindow *) 0);
-
- current_workspace->hideAll();
-
- current_workspace = getWorkspace(id);
-
- xatom->set(getRootWindow(), otk::OBProperty::net_current_desktop,
- otk::OBProperty::Atom_Cardinal, id);
-
- current_workspace->showAll();
-
- int x, y, rx, ry;
- Window c, r;
- unsigned int m;
- BlackboxWindow *win = (BlackboxWindow *) 0;
- bool f = False;
-
- XSync(otk::OBDisplay::display, False);
-
- // If sloppy focus and we can find the client window under the pointer,
- // try to focus it.
- if (resource.sloppy_focus &&
- XQueryPointer(otk::OBDisplay::display, getRootWindow(), &r, &c,
- &rx, &ry, &x, &y, &m) &&
- c != None) {
- if ( (win = blackbox->searchWindow(c)) )
- f = win->setInputFocus();
- }
-
- // If that fails, and we're doing focus_last, try to focus the last window.
- if (! f && resource.focus_last &&
- (win = current_workspace->getLastFocusedWindow()))
- f = win->setInputFocus();
-
- /*
- if we found a focus target, then we set the focused window explicitly
- because it is possible to switch off this workspace before the x server
- generates the FocusIn event for the window. if that happens, openbox would
- lose track of what window was the 'LastFocused' window on the workspace.
-
- if we did not find a focus target, then set the current focused window to
- nothing.
- */
- if (f)
- blackbox->setFocusedWindow(win);
- else
- blackbox->setFocusedWindow((BlackboxWindow *) 0);
-}
-