+ changeWorkspaceID(getCurrentWorkspaceID() - 1);
+ }
+}
+
+
+void BScreen::toggleFocusModel(FocusModel model) {
+ if (model == SloppyFocus) {
+ saveSloppyFocus(True);
+ } else {
+ // we're cheating here to save writing the config file 3 times
+ resource.auto_raise = False;
+ resource.click_raise = False;
+ saveSloppyFocus(False);
+ }
+
+ updateFocusModel();
+}
+
+
+void BScreen::updateFocusModel()
+{
+ std::for_each(workspacesList.begin(), workspacesList.end(),
+ std::mem_fun(&Workspace::updateFocusModel));
+}
+
+
+BTexture BScreen::readDatabaseTexture(const string &rname,
+ const string &default_color,
+ Configuration &style) {
+ BTexture texture;
+ string s;
+
+ if (style.getValue(rname, s))
+ texture = BTexture(s);
+ else
+ texture.setTexture(BTexture::Solid | BTexture::Flat);
+
+ // associate this texture with this screen
+ texture.setDisplay(getBaseDisplay(), getScreenNumber());
+ texture.setImageControl(image_control);
+
+ if (texture.texture() & BTexture::Solid) {
+ texture.setColor(readDatabaseColor(rname + ".color",
+ default_color, style));
+ texture.setColorTo(readDatabaseColor(rname + ".colorTo",
+ default_color, style));
+ } else if (texture.texture() & BTexture::Gradient) {
+ texture.setColor(readDatabaseColor(rname + ".color",
+ default_color, style));
+ texture.setColorTo(readDatabaseColor(rname + ".colorTo",
+ default_color, style));
+ }
+
+ return texture;
+}
+
+
+BColor BScreen::readDatabaseColor(const string &rname,
+ const string &default_color,
+ Configuration &style) {
+ BColor color;
+ string s;
+ if (style.getValue(rname, s))
+ color = BColor(s, getBaseDisplay(), getScreenNumber());
+ else
+ color = BColor(default_color, getBaseDisplay(), getScreenNumber());
+ return color;
+}
+
+
+XFontSet BScreen::readDatabaseFontSet(const string &rname,
+ Configuration &style) {
+ char *defaultFont = "fixed";
+
+ bool load_default = True;
+ string s;
+ XFontSet fontset = 0;
+ if (style.getValue(rname, s) && (fontset = createFontSet(s)))
+ load_default = False;
+
+ if (load_default) {
+ fontset = createFontSet(defaultFont);
+
+ if (! fontset) {
+ fprintf(stderr,
+ i18n(ScreenSet, ScreenDefaultFontLoadFail,
+ "BScreen::setCurrentStyle(): couldn't load default font.\n"));
+ exit(2);
+ }
+ }
+
+ return fontset;
+}
+
+
+XFontStruct *BScreen::readDatabaseFont(const string &rname,
+ Configuration &style) {
+ char *defaultFont = "fixed";
+
+ bool load_default = False;
+ string s;
+ XFontStruct *font = 0;
+ if (style.getValue(rname, s)) {
+ if ((font = XLoadQueryFont(blackbox->getXDisplay(), s.c_str())) == NULL) {
+ fprintf(stderr,
+ i18n(ScreenSet, ScreenFontLoadFail,
+ "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
+ s.c_str());
+
+ load_default = True;
+ }
+ } else {
+ load_default = True;
+ }
+
+ if (load_default) {
+ font = XLoadQueryFont(blackbox->getXDisplay(), defaultFont);
+ if (font == NULL) {
+ fprintf(stderr,
+ i18n(ScreenSet, ScreenDefaultFontLoadFail,
+ "BScreen::setCurrentStyle(): couldn't load default font.\n"));
+ exit(2);
+ }
+ }
+
+ return font;
+}
+
+
+#ifndef HAVE_STRCASESTR
+static const char * strcasestr(const char *str, const char *ptn) {
+ const char *s2, *p2;
+ for(; *str; str++) {
+ for(s2=str,p2=ptn; ; s2++,p2++) {
+ if (! *p2) return str;
+ if (toupper(*s2) != toupper(*p2)) break;
+ }
+ }
+ return NULL;
+}
+#endif // HAVE_STRCASESTR
+
+
+static const char *getFontElement(const char *pattern, char *buf,
+ int bufsiz, ...) {
+ const char *p, *v;
+ char *p2;
+ va_list va;
+
+ va_start(va, bufsiz);
+ buf[bufsiz-1] = 0;
+ buf[bufsiz-2] = '*';
+ while((v = va_arg(va, char *)) != NULL) {
+ p = strcasestr(pattern, v);
+ if (p) {
+ strncpy(buf, p+1, bufsiz-2);
+ p2 = strchr(buf, '-');
+ if (p2) *p2=0;
+ va_end(va);
+ return p;
+ }
+ }
+ va_end(va);
+ strncpy(buf, "*", bufsiz);
+ return NULL;
+}
+
+
+static const char *getFontSize(const char *pattern, int *size) {
+ const char *p;
+ const char *p2=NULL;
+ int n=0;
+
+ for (p=pattern; 1; p++) {
+ if (! *p) {
+ if (p2!=NULL && n>1 && n<72) {
+ *size = n; return p2+1;
+ } else {
+ *size = 16; return NULL;
+ }
+ } else if (*p=='-') {
+ if (n>1 && n<72 && p2!=NULL) {
+ *size = n;
+ return p2+1;
+ }
+ p2=p; n=0;
+ } else if (*p>='0' && *p<='9' && p2!=NULL) {
+ n *= 10;
+ n += *p-'0';
+ } else {
+ p2=NULL; n=0;
+ }
+ }
+}
+
+
+XFontSet BScreen::createFontSet(const string &fontname) {
+ XFontSet fs;
+ char **missing, *def = "-";
+ int nmissing, pixel_size = 0, buf_size = 0;
+ char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
+
+ fs = XCreateFontSet(blackbox->getXDisplay(),
+ fontname.c_str(), &missing, &nmissing, &def);
+ if (fs && (! nmissing))
+ return fs;
+
+ const char *nfontname = fontname.c_str();
+#ifdef HAVE_SETLOCALE
+ if (! fs) {
+ if (nmissing) XFreeStringList(missing);
+
+ setlocale(LC_CTYPE, "C");
+ fs = XCreateFontSet(blackbox->getXDisplay(), fontname.c_str(),
+ &missing, &nmissing, &def);
+ setlocale(LC_CTYPE, "");
+ }
+#endif // HAVE_SETLOCALE
+
+ if (fs) {
+ XFontStruct **fontstructs;
+ char **fontnames;
+ XFontsOfFontSet(fs, &fontstructs, &fontnames);
+ nfontname = fontnames[0];