xref: /haiku/src/servers/app/DesktopSettings.cpp (revision 5629675a326ecf2ff3fd23f154beb525c171048d)
1 /*
2  * Copyright 2005-2015, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  *		Axel Dörfler, axeld@pinc-software.de
8  *		Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk>
9  *		Joseph Groover <looncraz@looncraz.net>
10  */
11 
12 
13 #include "DesktopSettings.h"
14 #include "DesktopSettingsPrivate.h"
15 
16 #include <Directory.h>
17 #include <File.h>
18 #include <FindDirectory.h>
19 #include <Path.h>
20 
21 #include <DefaultColors.h>
22 #include <InterfaceDefs.h>
23 #include <ServerReadOnlyMemory.h>
24 
25 #include "Desktop.h"
26 #include "FontCache.h"
27 #include "FontCacheEntry.h"
28 #include "FontManager.h"
29 #include "GlobalSubpixelSettings.h"
30 #include "ServerConfig.h"
31 
32 
33 DesktopSettingsPrivate::DesktopSettingsPrivate(server_read_only_memory* shared)
34 	:
35 	fShared(*shared)
36 {
37 	// if the on-disk settings are not complete, the defaults will be kept
38 	_SetDefaults();
39 	_Load();
40 }
41 
42 
43 DesktopSettingsPrivate::~DesktopSettingsPrivate()
44 {
45 }
46 
47 
48 void
49 DesktopSettingsPrivate::_SetDefaults()
50 {
51 	fPlainFont = *gFontManager->DefaultPlainFont();
52 	fBoldFont = *gFontManager->DefaultBoldFont();
53 	fFixedFont = *gFontManager->DefaultFixedFont();
54 
55 	fMouseMode = B_NORMAL_MOUSE;
56 	fFocusFollowsMouseMode = B_NORMAL_FOCUS_FOLLOWS_MOUSE;
57 	fAcceptFirstClick = false;
58 	fShowAllDraggers = true;
59 
60 	// init scrollbar info
61 	fScrollBarInfo.proportional = true;
62 	fScrollBarInfo.double_arrows = false;
63 	fScrollBarInfo.knob = 0;
64 		// look of the knob (R5: (0, 1, 2), 1 = default)
65 		// change default = 0 (no knob) in Haiku
66 	fScrollBarInfo.min_knob_size = 15;
67 
68 	// init menu info
69 	strlcpy(fMenuInfo.f_family, fPlainFont.Family(), B_FONT_FAMILY_LENGTH);
70 	strlcpy(fMenuInfo.f_style, fPlainFont.Style(), B_FONT_STYLE_LENGTH);
71 	fMenuInfo.font_size = fPlainFont.Size();
72 	fMenuInfo.background_color.set_to(216, 216, 216);
73 
74 	fMenuInfo.separator = 0;
75 		// look of the separator (R5: (0, 1, 2), default 0)
76 	fMenuInfo.click_to_open = true; // always true
77 	fMenuInfo.triggers_always_shown = false;
78 
79 	fWorkspacesColumns = 2;
80 	fWorkspacesRows = 2;
81 
82 	memcpy(fShared.colors, BPrivate::kDefaultColors,
83 		sizeof(rgb_color) * kColorWhichCount);
84 
85 	gSubpixelAntialiasing = true;
86 	gDefaultHintingMode = HINTING_MODE_ON;
87 	gSubpixelAverageWeight = 120;
88 	gSubpixelOrderingRGB = true;
89 }
90 
91 
92 status_t
93 DesktopSettingsPrivate::_GetPath(BPath& path)
94 {
95 	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
96 	if (status < B_OK)
97 		return status;
98 
99 	status = path.Append("system/app_server");
100 	if (status < B_OK)
101 		return status;
102 
103 	return create_directory(path.Path(), 0755);
104 }
105 
106 
107 status_t
108 DesktopSettingsPrivate::_Load()
109 {
110 	// TODO: add support for old app_server_settings file as well
111 
112 	BPath basePath;
113 	status_t status = _GetPath(basePath);
114 	if (status < B_OK)
115 		return status;
116 
117 	// read workspaces settings
118 
119 	BPath path(basePath);
120 	path.Append("workspaces");
121 
122 	BFile file;
123 	status = file.SetTo(path.Path(), B_READ_ONLY);
124 	if (status == B_OK) {
125 		BMessage settings;
126 		status = settings.Unflatten(&file);
127 		if (status == B_OK) {
128 			int32 columns;
129 			int32 rows;
130 			if (settings.FindInt32("columns", &columns) == B_OK
131 				&& settings.FindInt32("rows", &rows) == B_OK) {
132 				_ValidateWorkspacesLayout(columns, rows);
133 				fWorkspacesColumns = columns;
134 				fWorkspacesRows = rows;
135 			}
136 
137 			int32 i = 0;
138 			while (i < kMaxWorkspaces && settings.FindMessage("workspace",
139 					i, &fWorkspaceMessages[i]) == B_OK) {
140 				i++;
141 			}
142 		}
143 	}
144 
145 	// read font settings
146 
147 	path = basePath;
148 	path.Append("fonts");
149 
150 	status = file.SetTo(path.Path(), B_READ_ONLY);
151 	if (status == B_OK) {
152 		BMessage settings;
153 		status = settings.Unflatten(&file);
154 		if (status == B_OK && gFontManager->Lock()) {
155 			const char* family;
156 			const char* style;
157 			float size;
158 
159 			if (settings.FindString("plain family", &family) == B_OK
160 				&& settings.FindString("plain style", &style) == B_OK
161 				&& settings.FindFloat("plain size", &size) == B_OK) {
162 				FontStyle* fontStyle = gFontManager->GetStyle(family, style);
163 				fPlainFont.SetStyle(fontStyle);
164 				fPlainFont.SetSize(size);
165 			}
166 
167 			if (settings.FindString("bold family", &family) == B_OK
168 				&& settings.FindString("bold style", &style) == B_OK
169 				&& settings.FindFloat("bold size", &size) == B_OK) {
170 				FontStyle* fontStyle = gFontManager->GetStyle(family, style);
171 				fBoldFont.SetStyle(fontStyle);
172 				fBoldFont.SetSize(size);
173 			}
174 
175 			if (settings.FindString("fixed family", &family) == B_OK
176 				&& settings.FindString("fixed style", &style) == B_OK
177 				&& settings.FindFloat("fixed size", &size) == B_OK) {
178 				FontStyle* fontStyle = gFontManager->GetStyle(family, style);
179 				if (fontStyle != NULL && fontStyle->IsFixedWidth())
180 					fFixedFont.SetStyle(fontStyle);
181 				fFixedFont.SetSize(size);
182 			}
183 
184 			int32 hinting;
185 			if (settings.FindInt32("hinting", &hinting) == B_OK)
186 				gDefaultHintingMode = hinting;
187 
188 			gFontManager->Unlock();
189 		}
190 	}
191 
192 	// read mouse settings
193 
194 	path = basePath;
195 	path.Append("mouse");
196 
197 	status = file.SetTo(path.Path(), B_READ_ONLY);
198 	if (status == B_OK) {
199 		BMessage settings;
200 		status = settings.Unflatten(&file);
201 		if (status == B_OK) {
202 			int32 mode;
203 			if (settings.FindInt32("mode", &mode) == B_OK)
204 				fMouseMode = (mode_mouse)mode;
205 
206 			int32 focusFollowsMouseMode;
207 			if (settings.FindInt32("focus follows mouse mode",
208 					&focusFollowsMouseMode) == B_OK) {
209 				fFocusFollowsMouseMode
210 					= (mode_focus_follows_mouse)focusFollowsMouseMode;
211 			}
212 
213 			bool acceptFirstClick;
214 			if (settings.FindBool("accept first click", &acceptFirstClick)
215 					== B_OK) {
216 				fAcceptFirstClick = acceptFirstClick;
217 			}
218 		}
219 	}
220 
221 	// read appearance settings
222 
223 	path = basePath;
224 	path.Append("appearance");
225 
226 	status = file.SetTo(path.Path(), B_READ_ONLY);
227 	if (status == B_OK) {
228 		BMessage settings;
229 		status = settings.Unflatten(&file);
230 		if (status == B_OK) {
231 			// menus
232 			float fontSize;
233 			if (settings.FindFloat("font size", &fontSize) == B_OK)
234 				fMenuInfo.font_size = fontSize;
235 
236 			const char* fontFamily;
237 			if (settings.FindString("font family", &fontFamily) == B_OK)
238 				strlcpy(fMenuInfo.f_family, fontFamily, B_FONT_FAMILY_LENGTH);
239 
240 			const char* fontStyle;
241 			if (settings.FindString("font style", &fontStyle) == B_OK)
242 				strlcpy(fMenuInfo.f_style, fontStyle, B_FONT_STYLE_LENGTH);
243 
244 			rgb_color bgColor;
245 			if (settings.FindInt32("bg color", (int32*)&bgColor) == B_OK)
246 				fMenuInfo.background_color = bgColor;
247 
248 			int32 separator;
249 			if (settings.FindInt32("separator", &separator) == B_OK)
250 				fMenuInfo.separator = separator;
251 
252 			bool clickToOpen;
253 			if (settings.FindBool("click to open", &clickToOpen) == B_OK)
254 				fMenuInfo.click_to_open = clickToOpen;
255 
256 			bool triggersAlwaysShown;
257 			if (settings.FindBool("triggers always shown", &triggersAlwaysShown)
258 					 == B_OK) {
259 				fMenuInfo.triggers_always_shown = triggersAlwaysShown;
260 			}
261 
262 			// scrollbars
263 			bool proportional;
264 			if (settings.FindBool("proportional", &proportional) == B_OK)
265 				fScrollBarInfo.proportional = proportional;
266 
267 			bool doubleArrows;
268 			if (settings.FindBool("double arrows", &doubleArrows) == B_OK)
269 				fScrollBarInfo.double_arrows = doubleArrows;
270 
271 			int32 knob;
272 			if (settings.FindInt32("knob", &knob) == B_OK)
273 				fScrollBarInfo.knob = knob;
274 
275 			int32 minKnobSize;
276 			if (settings.FindInt32("min knob size", &minKnobSize) == B_OK)
277 				fScrollBarInfo.min_knob_size = minKnobSize;
278 
279 			// subpixel font rendering
280 			bool subpix;
281 			if (settings.FindBool("subpixel antialiasing", &subpix) == B_OK)
282 				gSubpixelAntialiasing = subpix;
283 
284 			int8 averageWeight;
285 			if (settings.FindInt8("subpixel average weight", &averageWeight)
286 					== B_OK) {
287 				gSubpixelAverageWeight = averageWeight;
288 			}
289 
290 			bool subpixelOrdering;
291 			if (settings.FindBool("subpixel ordering", &subpixelOrdering)
292 					== B_OK) {
293 				gSubpixelOrderingRGB = subpixelOrdering;
294 			}
295 
296 			// colors
297 			for (int32 i = 0; i < kColorWhichCount; i++) {
298 				char colorName[12];
299 				snprintf(colorName, sizeof(colorName), "color%" B_PRId32,
300 					(int32)index_to_color_which(i));
301 
302 				if (settings.FindInt32(colorName, (int32*)&fShared.colors[i]) != B_OK) {
303 					// Set obviously bad value so the Appearance app can detect it
304 					fShared.colors[i] = B_TRANSPARENT_COLOR;
305 				}
306 			}
307 		}
308 	}
309 
310 	// read dragger settings
311 
312 	path = basePath;
313 	path.Append("dragger");
314 
315 	status = file.SetTo(path.Path(), B_READ_ONLY);
316 	if (status == B_OK) {
317 		BMessage settings;
318 		status = settings.Unflatten(&file);
319 		if (status == B_OK) {
320 			if (settings.FindBool("show", &fShowAllDraggers) != B_OK)
321 				fShowAllDraggers = true;
322 		}
323 	}
324 
325 	return B_OK;
326 }
327 
328 
329 status_t
330 DesktopSettingsPrivate::Save(uint32 mask)
331 {
332 #if TEST_MODE
333 	return B_OK;
334 #endif
335 
336 	BPath basePath;
337 	status_t status = _GetPath(basePath);
338 	if (status != B_OK)
339 		return status;
340 
341 	if (mask & kWorkspacesSettings) {
342 		BPath path(basePath);
343 		if (path.Append("workspaces") == B_OK) {
344 			BMessage settings('asws');
345 			settings.AddInt32("columns", fWorkspacesColumns);
346 			settings.AddInt32("rows", fWorkspacesRows);
347 
348 			for (int32 i = 0; i < kMaxWorkspaces; i++) {
349 				settings.AddMessage("workspace", &fWorkspaceMessages[i]);
350 			}
351 
352 			BFile file;
353 			status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
354 				| B_READ_WRITE);
355 			if (status == B_OK) {
356 				status = settings.Flatten(&file, NULL);
357 			}
358 		}
359 	}
360 
361 	if (mask & kFontSettings) {
362 		BPath path(basePath);
363 		if (path.Append("fonts") == B_OK) {
364 			BMessage settings('asfn');
365 
366 			settings.AddString("plain family", fPlainFont.Family());
367 			settings.AddString("plain style", fPlainFont.Style());
368 			settings.AddFloat("plain size", fPlainFont.Size());
369 
370 			settings.AddString("bold family", fBoldFont.Family());
371 			settings.AddString("bold style", fBoldFont.Style());
372 			settings.AddFloat("bold size", fBoldFont.Size());
373 
374 			settings.AddString("fixed family", fFixedFont.Family());
375 			settings.AddString("fixed style", fFixedFont.Style());
376 			settings.AddFloat("fixed size", fFixedFont.Size());
377 
378 			settings.AddInt32("hinting", gDefaultHintingMode);
379 
380 			BFile file;
381 			status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
382 				| B_READ_WRITE);
383 			if (status == B_OK) {
384 				status = settings.Flatten(&file, NULL);
385 			}
386 		}
387 	}
388 
389 	if (mask & kMouseSettings) {
390 		BPath path(basePath);
391 		if (path.Append("mouse") == B_OK) {
392 			BMessage settings('asms');
393 			settings.AddInt32("mode", (int32)fMouseMode);
394 			settings.AddInt32("focus follows mouse mode",
395 				(int32)fFocusFollowsMouseMode);
396 			settings.AddBool("accept first click", fAcceptFirstClick);
397 
398 			BFile file;
399 			status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
400 				| B_READ_WRITE);
401 			if (status == B_OK) {
402 				status = settings.Flatten(&file, NULL);
403 			}
404 		}
405 	}
406 
407 	if (mask & kDraggerSettings) {
408 		BPath path(basePath);
409 		if (path.Append("dragger") == B_OK) {
410 			BMessage settings('asdg');
411 			settings.AddBool("show", fShowAllDraggers);
412 
413 			BFile file;
414 			status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
415 				| B_READ_WRITE);
416 			if (status == B_OK) {
417 				status = settings.Flatten(&file, NULL);
418 			}
419 		}
420 	}
421 
422 	if (mask & kAppearanceSettings) {
423 		BPath path(basePath);
424 		if (path.Append("appearance") == B_OK) {
425 			BMessage settings('aslk');
426 			settings.AddFloat("font size", fMenuInfo.font_size);
427 			settings.AddString("font family", fMenuInfo.f_family);
428 			settings.AddString("font style", fMenuInfo.f_style);
429 			settings.AddInt32("bg color",
430 				(const int32&)fMenuInfo.background_color);
431 			settings.AddInt32("separator", fMenuInfo.separator);
432 			settings.AddBool("click to open", fMenuInfo.click_to_open);
433 			settings.AddBool("triggers always shown",
434 				fMenuInfo.triggers_always_shown);
435 
436 			settings.AddBool("proportional", fScrollBarInfo.proportional);
437 			settings.AddBool("double arrows", fScrollBarInfo.double_arrows);
438 			settings.AddInt32("knob", fScrollBarInfo.knob);
439 			settings.AddInt32("min knob size", fScrollBarInfo.min_knob_size);
440 
441 			settings.AddBool("subpixel antialiasing", gSubpixelAntialiasing);
442 			settings.AddInt8("subpixel average weight", gSubpixelAverageWeight);
443 			settings.AddBool("subpixel ordering", gSubpixelOrderingRGB);
444 
445 			for (int32 i = 0; i < kColorWhichCount; i++) {
446 				char colorName[12];
447 				snprintf(colorName, sizeof(colorName), "color%" B_PRId32,
448 					(int32)index_to_color_which(i));
449 				settings.AddInt32(colorName, (const int32&)fShared.colors[i]);
450 			}
451 
452 			BFile file;
453 			status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE
454 				| B_READ_WRITE);
455 			if (status == B_OK) {
456 				status = settings.Flatten(&file, NULL);
457 			}
458 		}
459 	}
460 
461 	return status;
462 }
463 
464 
465 void
466 DesktopSettingsPrivate::SetDefaultPlainFont(const ServerFont &font)
467 {
468 	fPlainFont = font;
469 	Save(kFontSettings);
470 }
471 
472 
473 const ServerFont &
474 DesktopSettingsPrivate::DefaultPlainFont() const
475 {
476 	return fPlainFont;
477 }
478 
479 
480 void
481 DesktopSettingsPrivate::SetDefaultBoldFont(const ServerFont &font)
482 {
483 	fBoldFont = font;
484 	Save(kFontSettings);
485 }
486 
487 
488 const ServerFont &
489 DesktopSettingsPrivate::DefaultBoldFont() const
490 {
491 	return fBoldFont;
492 }
493 
494 
495 void
496 DesktopSettingsPrivate::SetDefaultFixedFont(const ServerFont &font)
497 {
498 	fFixedFont = font;
499 	Save(kFontSettings);
500 }
501 
502 
503 const ServerFont &
504 DesktopSettingsPrivate::DefaultFixedFont() const
505 {
506 	return fFixedFont;
507 }
508 
509 
510 void
511 DesktopSettingsPrivate::SetScrollBarInfo(const scroll_bar_info& info)
512 {
513 	fScrollBarInfo = info;
514 	Save(kAppearanceSettings);
515 }
516 
517 
518 const scroll_bar_info&
519 DesktopSettingsPrivate::ScrollBarInfo() const
520 {
521 	return fScrollBarInfo;
522 }
523 
524 
525 void
526 DesktopSettingsPrivate::SetMenuInfo(const menu_info& info)
527 {
528 	fMenuInfo = info;
529 	// Also update the ui_color
530 	SetUIColor(B_MENU_BACKGROUND_COLOR, info.background_color);
531 		// SetUIColor already saves the settings
532 }
533 
534 
535 const menu_info&
536 DesktopSettingsPrivate::MenuInfo() const
537 {
538 	return fMenuInfo;
539 }
540 
541 
542 void
543 DesktopSettingsPrivate::SetMouseMode(const mode_mouse mode)
544 {
545 	fMouseMode = mode;
546 	Save(kMouseSettings);
547 }
548 
549 
550 void
551 DesktopSettingsPrivate::SetFocusFollowsMouseMode(mode_focus_follows_mouse mode)
552 {
553 	fFocusFollowsMouseMode = mode;
554 	Save(kMouseSettings);
555 }
556 
557 
558 mode_mouse
559 DesktopSettingsPrivate::MouseMode() const
560 {
561 	return fMouseMode;
562 }
563 
564 
565 mode_focus_follows_mouse
566 DesktopSettingsPrivate::FocusFollowsMouseMode() const
567 {
568 	return fFocusFollowsMouseMode;
569 }
570 
571 
572 void
573 DesktopSettingsPrivate::SetAcceptFirstClick(const bool acceptFirstClick)
574 {
575 	fAcceptFirstClick = acceptFirstClick;
576 	Save(kMouseSettings);
577 }
578 
579 
580 bool
581 DesktopSettingsPrivate::AcceptFirstClick() const
582 {
583 	return fAcceptFirstClick;
584 }
585 
586 
587 void
588 DesktopSettingsPrivate::SetShowAllDraggers(bool show)
589 {
590 	fShowAllDraggers = show;
591 	Save(kDraggerSettings);
592 }
593 
594 
595 bool
596 DesktopSettingsPrivate::ShowAllDraggers() const
597 {
598 	return fShowAllDraggers;
599 }
600 
601 
602 void
603 DesktopSettingsPrivate::SetWorkspacesLayout(int32 columns, int32 rows)
604 {
605 	_ValidateWorkspacesLayout(columns, rows);
606 	fWorkspacesColumns = columns;
607 	fWorkspacesRows = rows;
608 
609 	Save(kWorkspacesSettings);
610 }
611 
612 
613 int32
614 DesktopSettingsPrivate::WorkspacesCount() const
615 {
616 	return fWorkspacesColumns * fWorkspacesRows;
617 }
618 
619 
620 int32
621 DesktopSettingsPrivate::WorkspacesColumns() const
622 {
623 	return fWorkspacesColumns;
624 }
625 
626 
627 int32
628 DesktopSettingsPrivate::WorkspacesRows() const
629 {
630 	return fWorkspacesRows;
631 }
632 
633 
634 void
635 DesktopSettingsPrivate::SetWorkspacesMessage(int32 index, BMessage& message)
636 {
637 	if (index < 0 || index >= kMaxWorkspaces)
638 		return;
639 
640 	fWorkspaceMessages[index] = message;
641 }
642 
643 
644 const BMessage*
645 DesktopSettingsPrivate::WorkspacesMessage(int32 index) const
646 {
647 	if (index < 0 || index >= kMaxWorkspaces)
648 		return NULL;
649 
650 	return &fWorkspaceMessages[index];
651 }
652 
653 
654 void
655 DesktopSettingsPrivate::SetUIColor(color_which which, const rgb_color color,
656 									bool* changed)
657 {
658 	int32 index = color_which_to_index(which);
659 	if (index < 0 || index >= kColorWhichCount)
660 		return;
661 
662 	if (changed != NULL)
663 		*changed = fShared.colors[index] != color;
664 
665 	fShared.colors[index] = color;
666 	// TODO: deprecate the background_color member of the menu_info struct,
667 	// otherwise we have to keep this duplication...
668 	if (which == B_MENU_BACKGROUND_COLOR)
669 		fMenuInfo.background_color = color;
670 
671 	Save(kAppearanceSettings);
672 }
673 
674 
675 void
676 DesktopSettingsPrivate::SetUIColors(const BMessage& colors, bool* changed)
677 {
678 	int32 count = colors.CountNames(B_RGB_32_BIT_TYPE);
679 	if (count <= 0)
680 		return;
681 
682 	int32 index = 0;
683 	int32 colorIndex = 0;
684 	char* name = NULL;
685 	type_code type;
686 	rgb_color color;
687 	color_which which = B_NO_COLOR;
688 
689 	while (colors.GetInfo(B_RGB_32_BIT_TYPE, index, &name, &type) == B_OK) {
690 		which = which_ui_color(name);
691 		colorIndex = color_which_to_index(which);
692 		if (colorIndex < 0 || colorIndex >= kColorWhichCount
693 			|| colors.FindColor(name, &color) != B_OK) {
694 			if (changed != NULL)
695 				changed[index] = false;
696 
697 			++index;
698 			continue;
699 		}
700 
701 		if (changed != NULL)
702 			changed[index] = fShared.colors[colorIndex] != color;
703 
704 		fShared.colors[colorIndex] = color;
705 
706 		if (which == (int32)B_MENU_BACKGROUND_COLOR)
707 			fMenuInfo.background_color = color;
708 
709 		++index;
710 	}
711 
712 	Save(kAppearanceSettings);
713 }
714 
715 
716 rgb_color
717 DesktopSettingsPrivate::UIColor(color_which which) const
718 {
719 	static const rgb_color invalidColor = {0, 0, 0, 0};
720 	int32 index = color_which_to_index(which);
721 	if (index < 0 || index >= kColorWhichCount)
722 		return invalidColor;
723 
724 	return fShared.colors[index];
725 }
726 
727 
728 void
729 DesktopSettingsPrivate::SetSubpixelAntialiasing(bool subpix)
730 {
731 	gSubpixelAntialiasing = subpix;
732 	Save(kAppearanceSettings);
733 }
734 
735 
736 bool
737 DesktopSettingsPrivate::SubpixelAntialiasing() const
738 {
739 	return gSubpixelAntialiasing;
740 }
741 
742 
743 void
744 DesktopSettingsPrivate::SetHinting(uint8 hinting)
745 {
746 	gDefaultHintingMode = hinting;
747 	Save(kFontSettings);
748 }
749 
750 
751 uint8
752 DesktopSettingsPrivate::Hinting() const
753 {
754 	return gDefaultHintingMode;
755 }
756 
757 
758 void
759 DesktopSettingsPrivate::SetSubpixelAverageWeight(uint8 averageWeight)
760 {
761 	gSubpixelAverageWeight = averageWeight;
762 	Save(kAppearanceSettings);
763 }
764 
765 
766 uint8
767 DesktopSettingsPrivate::SubpixelAverageWeight() const
768 {
769 	return gSubpixelAverageWeight;
770 }
771 
772 
773 void
774 DesktopSettingsPrivate::SetSubpixelOrderingRegular(bool subpixelOrdering)
775 {
776 	gSubpixelOrderingRGB = subpixelOrdering;
777 	Save(kAppearanceSettings);
778 }
779 
780 
781 bool
782 DesktopSettingsPrivate::IsSubpixelOrderingRegular() const
783 {
784 	return gSubpixelOrderingRGB;
785 }
786 
787 
788 void
789 DesktopSettingsPrivate::_ValidateWorkspacesLayout(int32& columns,
790 	int32& rows) const
791 {
792 	if (columns < 1)
793 		columns = 1;
794 	if (rows < 1)
795 		rows = 1;
796 
797 	if (columns * rows > kMaxWorkspaces) {
798 		// Revert to defaults in case of invalid settings
799 		columns = 2;
800 		rows = 2;
801 	}
802 }
803 
804 
805 //	#pragma mark - read access
806 
807 
808 DesktopSettings::DesktopSettings(Desktop* desktop)
809 	:
810 	fSettings(desktop->fSettings)
811 {
812 
813 }
814 
815 
816 void
817 DesktopSettings::GetDefaultPlainFont(ServerFont &font) const
818 {
819 	font = fSettings->DefaultPlainFont();
820 }
821 
822 
823 void
824 DesktopSettings::GetDefaultBoldFont(ServerFont &font) const
825 {
826 	font = fSettings->DefaultBoldFont();
827 }
828 
829 
830 void
831 DesktopSettings::GetDefaultFixedFont(ServerFont &font) const
832 {
833 	font = fSettings->DefaultFixedFont();
834 }
835 
836 
837 void
838 DesktopSettings::GetScrollBarInfo(scroll_bar_info& info) const
839 {
840 	info = fSettings->ScrollBarInfo();
841 }
842 
843 
844 void
845 DesktopSettings::GetMenuInfo(menu_info& info) const
846 {
847 	info = fSettings->MenuInfo();
848 }
849 
850 
851 mode_mouse
852 DesktopSettings::MouseMode() const
853 {
854 	return fSettings->MouseMode();
855 }
856 
857 
858 mode_focus_follows_mouse
859 DesktopSettings::FocusFollowsMouseMode() const
860 {
861 	return fSettings->FocusFollowsMouseMode();
862 }
863 
864 
865 bool
866 DesktopSettings::AcceptFirstClick() const
867 {
868 	return fSettings->AcceptFirstClick();
869 }
870 
871 
872 bool
873 DesktopSettings::ShowAllDraggers() const
874 {
875 	return fSettings->ShowAllDraggers();
876 }
877 
878 
879 int32
880 DesktopSettings::WorkspacesCount() const
881 {
882 	return fSettings->WorkspacesCount();
883 }
884 
885 
886 int32
887 DesktopSettings::WorkspacesColumns() const
888 {
889 	return fSettings->WorkspacesColumns();
890 }
891 
892 
893 int32
894 DesktopSettings::WorkspacesRows() const
895 {
896 	return fSettings->WorkspacesRows();
897 }
898 
899 
900 const BMessage*
901 DesktopSettings::WorkspacesMessage(int32 index) const
902 {
903 	return fSettings->WorkspacesMessage(index);
904 }
905 
906 
907 rgb_color
908 DesktopSettings::UIColor(color_which which) const
909 {
910 	return fSettings->UIColor(which);
911 }
912 
913 
914 bool
915 DesktopSettings::SubpixelAntialiasing() const
916 {
917 	return fSettings->SubpixelAntialiasing();
918 }
919 
920 
921 uint8
922 DesktopSettings::Hinting() const
923 {
924 	return fSettings->Hinting();
925 }
926 
927 
928 uint8
929 DesktopSettings::SubpixelAverageWeight() const
930 {
931 	return fSettings->SubpixelAverageWeight();
932 }
933 
934 
935 bool
936 DesktopSettings::IsSubpixelOrderingRegular() const
937 {
938 	// True corresponds to RGB, false means BGR
939 	return fSettings->IsSubpixelOrderingRegular();
940 }
941 
942 //	#pragma mark - write access
943 
944 
945 LockedDesktopSettings::LockedDesktopSettings(Desktop* desktop)
946 	:
947 	DesktopSettings(desktop),
948 	fDesktop(desktop)
949 {
950 #if DEBUG
951 	if (desktop->fWindowLock.IsReadLocked())
952 		debugger("desktop read locked when trying to change settings");
953 #endif
954 
955 	fDesktop->LockAllWindows();
956 }
957 
958 
959 LockedDesktopSettings::~LockedDesktopSettings()
960 {
961 	fDesktop->UnlockAllWindows();
962 }
963 
964 
965 void
966 LockedDesktopSettings::SetDefaultPlainFont(const ServerFont &font)
967 {
968 	fSettings->SetDefaultPlainFont(font);
969 }
970 
971 
972 void
973 LockedDesktopSettings::SetDefaultBoldFont(const ServerFont &font)
974 {
975 	fSettings->SetDefaultBoldFont(font);
976 	fDesktop->BroadcastToAllWindows(AS_SYSTEM_FONT_CHANGED);
977 }
978 
979 
980 void
981 LockedDesktopSettings::SetDefaultFixedFont(const ServerFont &font)
982 {
983 	fSettings->SetDefaultFixedFont(font);
984 }
985 
986 
987 void
988 LockedDesktopSettings::SetScrollBarInfo(const scroll_bar_info& info)
989 {
990 	fSettings->SetScrollBarInfo(info);
991 }
992 
993 
994 void
995 LockedDesktopSettings::SetMenuInfo(const menu_info& info)
996 {
997 	fSettings->SetMenuInfo(info);
998 }
999 
1000 
1001 void
1002 LockedDesktopSettings::SetMouseMode(const mode_mouse mode)
1003 {
1004 	fSettings->SetMouseMode(mode);
1005 }
1006 
1007 
1008 void
1009 LockedDesktopSettings::SetFocusFollowsMouseMode(mode_focus_follows_mouse mode)
1010 {
1011 	fSettings->SetFocusFollowsMouseMode(mode);
1012 }
1013 
1014 
1015 void
1016 LockedDesktopSettings::SetAcceptFirstClick(const bool acceptFirstClick)
1017 {
1018 	fSettings->SetAcceptFirstClick(acceptFirstClick);
1019 }
1020 
1021 
1022 void
1023 LockedDesktopSettings::SetShowAllDraggers(bool show)
1024 {
1025 	fSettings->SetShowAllDraggers(show);
1026 }
1027 
1028 
1029 void
1030 LockedDesktopSettings::SetUIColors(const BMessage& colors, bool* changed)
1031 {
1032 	fSettings->SetUIColors(colors, &changed[0]);
1033 }
1034 
1035 
1036 void
1037 LockedDesktopSettings::SetSubpixelAntialiasing(bool subpix)
1038 {
1039 	fSettings->SetSubpixelAntialiasing(subpix);
1040 }
1041 
1042 
1043 void
1044 LockedDesktopSettings::SetHinting(uint8 hinting)
1045 {
1046 	fSettings->SetHinting(hinting);
1047 }
1048 
1049 
1050 void
1051 LockedDesktopSettings::SetSubpixelAverageWeight(uint8 averageWeight)
1052 {
1053 	fSettings->SetSubpixelAverageWeight(averageWeight);
1054 }
1055 
1056 void
1057 LockedDesktopSettings::SetSubpixelOrderingRegular(bool subpixelOrdering)
1058 {
1059 	fSettings->SetSubpixelOrderingRegular(subpixelOrdering);
1060 }
1061 
1062