+void BScreen::saveSloppyFocus(bool s) {
+ resource.sloppy_focus = s;
+
+ string fmodel;
+ if (resource.sloppy_focus) {
+ fmodel = "SloppyFocus";
+ if (resource.auto_raise) fmodel += " AutoRaise";
+ if (resource.click_raise) fmodel += " ClickRaise";
+ } else {
+ fmodel = "ClickToFocus";
+ }
+ config->setValue(screenstr + "focusModel", fmodel);
+}
+
+
+void BScreen::saveAutoRaise(bool a) {
+ resource.auto_raise = a;
+ saveSloppyFocus(resource.sloppy_focus);
+}
+
+
+void BScreen::saveClickRaise(bool c) {
+ resource.click_raise = c;
+ saveSloppyFocus(resource.sloppy_focus);
+}
+
+
+void BScreen::saveImageDither(bool d) {
+ image_control->setDither(d);
+ config->setValue(screenstr + "imageDither", doImageDither());
+}
+
+
+void BScreen::saveOpaqueMove(bool o) {
+ resource.opaque_move = o;
+ config->setValue(screenstr + "opaqueMove", resource.opaque_move);
+}
+
+
+void BScreen::saveFullMax(bool f) {
+ resource.full_max = f;
+ config->setValue(screenstr + "fullMaximization", resource.full_max);
+}
+
+
+void BScreen::saveFocusNew(bool f) {
+ resource.focus_new = f;
+ config->setValue(screenstr + "focusNewWindows", resource.focus_new);
+}
+
+
+void BScreen::saveFocusLast(bool f) {
+ resource.focus_last = f;
+ config->setValue(screenstr + "focusLastWindow", resource.focus_last);
+}
+
+
+void BScreen::saveAAFonts(bool f) {
+ resource.aa_fonts = f;
+ config->setValue(screenstr + "antialiasFonts", resource.aa_fonts);
+ reconfigure();
+}
+
+
+void BScreen::saveShadowFonts(bool f) {
+ resource.shadow_fonts = f;
+ config->setValue(screenstr + "dropShadowFonts", resource.shadow_fonts);
+ reconfigure();
+}
+
+
+void BScreen::saveHideToolbar(bool h) {
+ resource.hide_toolbar = h;
+ if (resource.hide_toolbar)
+ toolbar->unmapToolbar();
+ else
+ toolbar->mapToolbar();
+ config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
+}
+
+
+void BScreen::saveWindowToEdgeSnap(int s) {
+ resource.snap_to_edges = s;
+
+ const char *snap;
+ switch (resource.snap_to_edges) {
+ case WindowNoSnap: snap = "NoSnap"; break;
+ case WindowResistance: snap = "Resistance"; break;
+ case WindowSnap: default: snap = "Snap"; break;
+ }
+ config->setValue(screenstr + "windowToEdgeSnap", snap);
+}
+
+
+void BScreen::saveWindowToWindowSnap(int s) {
+ resource.snap_to_windows = s;
+
+ const char *snap;
+ switch (resource.snap_to_windows) {
+ case WindowNoSnap: snap = "NoSnap"; break;
+ case WindowResistance: snap = "Resistance"; break;
+ case WindowSnap: default: snap = "Snap"; break;
+ }
+ config->setValue(screenstr + "windowToWindowSnap", snap);
+}
+
+
+void BScreen::saveResizeZones(unsigned int z) {
+ resource.resize_zones = z;
+ config->setValue(screenstr + "resizeZones", resource.resize_zones);
+}
+
+
+void BScreen::saveWindowCornerSnap(bool s) {
+ resource.window_corner_snap = s;
+ config->setValue(screenstr + "windowCornerSnap",
+ resource.window_corner_snap);
+}
+
+
+void BScreen::saveWorkspaces(unsigned int w) {
+ resource.workspaces = w;
+ config->setValue(screenstr + "workspaces", resource.workspaces);
+}
+
+
+void BScreen::savePlacementPolicy(int p) {
+ resource.placement_policy = p;
+ const char *placement;
+ switch (resource.placement_policy) {
+ case CascadePlacement: placement = "CascadePlacement"; break;
+ case UnderMousePlacement: placement = "UnderMousePlacement"; break;
+ case ClickMousePlacement: placement = "ClickMousePlacement"; break;
+ case ColSmartPlacement: placement = "ColSmartPlacement"; break;
+ case RowSmartPlacement: default: placement = "RowSmartPlacement"; break;
+ }
+ config->setValue(screenstr + "windowPlacement", placement);
+}
+
+
+void BScreen::saveResistanceSize(int s) {
+ resource.resistance_size = s;
+ config->setValue(screenstr + "resistanceSize",
+ resource.resistance_size);
+}
+
+
+void BScreen::saveSnapThreshold(int t) {
+ resource.snap_threshold = t;
+ config->setValue(screenstr + "edgeSnapThreshold",
+ resource.snap_threshold);
+}
+
+
+void BScreen::saveSnapOffset(int t) {
+ resource.snap_offset = t;
+ config->setValue(screenstr + "edgeSnapOffset",
+ resource.snap_offset);
+}
+
+
+void BScreen::saveRowPlacementDirection(int d) {
+ resource.row_direction = d;
+ config->setValue(screenstr + "rowPlacementDirection",
+ resource.row_direction == LeftRight ?
+ "LeftToRight" : "RightToLeft");
+}
+
+
+void BScreen::saveColPlacementDirection(int d) {
+ resource.col_direction = d;
+ config->setValue(screenstr + "colPlacementDirection",
+ resource.col_direction == TopBottom ?
+ "TopToBottom" : "BottomToTop");
+}
+
+
+#ifdef HAVE_STRFTIME
+void BScreen::saveStrftimeFormat(const std::string& format) {
+ resource.strftime_format = format;
+ config->setValue(screenstr + "strftimeFormat", resource.strftime_format);
+}
+
+#else // !HAVE_STRFTIME
+
+void BScreen::saveDateFormat(int f) {
+ resource.date_format = f;
+ config->setValue(screenstr + "dateFormat",
+ resource.date_format == B_EuropeanDate ?
+ "European" : "American");
+}
+
+
+void BScreen::saveClock24Hour(bool c) {
+ resource.clock24hour = c;
+ config->setValue(screenstr + "clockFormat", resource.clock24hour ? 24 : 12);
+}
+#endif // HAVE_STRFTIME
+
+
+void BScreen::saveWorkspaceNames() {
+ string names;
+
+ for (unsigned int i = 0; i < workspacesList.size(); ++i) {
+ names += workspacesList[i]->getName();
+ if (i < workspacesList.size() - 1)
+ names += ',';
+ }
+
+ config->setValue(screenstr + "workspaceNames", names);
+}
+
+
+void BScreen::savePlaceIgnoreShaded(bool i) {
+ resource.ignore_shaded = i;
+ config->setValue(screenstr + "placementIgnoreShaded",
+ resource.ignore_shaded);
+}
+
+
+void BScreen::savePlaceIgnoreMaximized(bool i) {
+ resource.ignore_maximized = i;
+ config->setValue(screenstr + "placementIgnoreMaximized",
+ resource.ignore_maximized);
+}
+
+
+void BScreen::saveAllowScrollLock(bool a) {
+ resource.allow_scroll_lock = a;
+ config->setValue(screenstr + "disableBindingsWithScrollLock",
+ resource.allow_scroll_lock);
+}
+
+
+void BScreen::saveWorkspaceWarping(bool w) {
+ resource.workspace_warping = w;
+ config->setValue(screenstr + "workspaceWarping",
+ resource.workspace_warping);
+}
+
+
+void BScreen::saveRootScrollDirection(int d) {
+ resource.root_scroll = d;
+ const char *dir;
+ switch (resource.root_scroll) {
+ case NoScroll: dir = "None"; break;
+ case ReverseScroll: dir = "Reverse"; break;
+ case NormalScroll: default: dir = "Normal"; break;
+ }
+ config->setValue(screenstr + "rootScrollDirection", dir);
+}
+
+
+void BScreen::saveRootMenuButton(unsigned int b) {
+ resource.root_menu_button = b;
+ const char *but;
+ switch (resource.root_menu_button) {
+ case 0: but = "None"; break;
+ case 1: but = "Left"; break;
+ case 2: but = "Middle"; break;
+ case 3: default: but = "Right"; break;
+ }
+ config->setValue(screenstr + "rootMenuButton", but);
+}
+
+
+void BScreen::saveWorkspaceMenuButton(unsigned int b) {
+ resource.workspace_menu_button = b;
+ const char *but;
+ switch (resource.workspace_menu_button) {
+ case 0: but = "None"; break;
+ case 1: but = "Left"; break;
+ case 2: default: but = "Middle"; break;
+ case 3: but = "Right"; break;
+ }
+ config->setValue(screenstr + "workspaceMenuButton", but);
+}
+
+
+void BScreen::save_rc(void) {
+ saveSloppyFocus(resource.sloppy_focus);
+ saveAutoRaise(resource.auto_raise);
+ saveImageDither(doImageDither());
+ saveShadowFonts(resource.shadow_fonts);
+ saveAAFonts(resource.aa_fonts);
+ saveResizeZones(resource.resize_zones);
+ saveOpaqueMove(resource.opaque_move);
+ saveFullMax(resource.full_max);
+ saveFocusNew(resource.focus_new);
+ saveFocusLast(resource.focus_last);
+ saveHideToolbar(resource.hide_toolbar);
+ saveWindowToWindowSnap(resource.snap_to_windows);
+ saveWindowToEdgeSnap(resource.snap_to_edges);
+ saveWindowCornerSnap(resource.window_corner_snap);
+ saveWorkspaces(resource.workspaces);
+ savePlacementPolicy(resource.placement_policy);
+ saveSnapThreshold(resource.snap_threshold);
+ saveSnapOffset(resource.snap_offset);
+ saveResistanceSize(resource.resistance_size);
+ saveRowPlacementDirection(resource.row_direction);
+ saveColPlacementDirection(resource.col_direction);
+#ifdef HAVE_STRFTIME
+ saveStrftimeFormat(resource.strftime_format);
+#else // !HAVE_STRFTIME
+ saveDateFormat(resource.date_format);
+ savwClock24Hour(resource.clock24hour);
+#endif // HAVE_STRFTIME
+ savePlaceIgnoreShaded(resource.ignore_shaded);
+ savePlaceIgnoreMaximized(resource.ignore_maximized);
+ saveAllowScrollLock(resource.allow_scroll_lock);
+ saveWorkspaceWarping(resource.workspace_warping);
+ saveRootScrollDirection(resource.root_scroll);
+ saveRootMenuButton(resource.root_menu_button);
+ saveWorkspaceMenuButton(resource.workspace_menu_button);
+
+ toolbar->save_rc();
+ slit->save_rc();
+}
+
+
+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;
+
+ if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
+ resource.hide_toolbar = false;
+
+ 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)) {
+ XAtom::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->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::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;
+
+#ifdef HAVE_STRFTIME
+ if (! config->getValue(screenstr + "strftimeFormat",
+ resource.strftime_format))
+ resource.strftime_format = "%I:%M %p";
+#else // !HAVE_STRFTIME
+ long l;
+
+ if (config->getValue(screenstr + "dateFormat", s) && s == "European")
+ resource.date_format = B_EuropeanDate;
+ else
+ resource.date_format = B_AmericanDate;
+
+ if (! config->getValue(screenstr + "clockFormat", l))
+ l = 12;
+ resource.clock24hour = l == 24;
+#endif // HAVE_STRFTIME
+
+ 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;
+ }
+
+ resource.root_menu_button = 3;
+ if (config->getValue(screenstr + "rootMenuButton", s)) {
+ if (s == "None")
+ resource.root_menu_button = 0;
+ else if (s == "Left")
+ resource.root_menu_button = 1;
+ else if (s == "Middle")
+ resource.root_menu_button = 2;
+ }
+
+ resource.workspace_menu_button = 2;
+ if (config->getValue(screenstr + "workspaceMenuButton", s)) {
+ if (s == "None")
+ resource.workspace_menu_button = 0;
+ else if (s == "Left")
+ resource.workspace_menu_button = 1;
+ else if (s == "Right")
+ resource.workspace_menu_button = 3;
+ }
+ // cant both be the same
+ if (resource.workspace_menu_button == resource.root_menu_button)
+ resource.workspace_menu_button = 0;
+}
+
+
+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();
+ }