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