xref: /haiku/src/add-ons/accelerants/radeon/settings.cpp (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*
2 	Copyright (c) 2002, Thomas Kurschel
3 
4 
5 	Part of Radeon accelerant
6 
7 	Settings file
8 
9 	We shouldn't really need settings as this info
10 	should be stored by app_server, but especially
11 	BWindowScreen programs cannot now about extra
12 	features/settings, so we need to store the flags
13 	internally (until I have a better idea ;)
14 
15 	Especially "SwapWindow" should be mode-independant
16 	(you don't swap monitors when you select another
17 	workspace, do you?)
18 */
19 
20 #include "radeon_accelerant.h"
21 #include "generic.h"
22 #include "GlobalData.h"
23 
24 #ifdef ENABLE_SETTINGS_FILE
25 #include <FindDirectory.h>
26 #include <Path.h>
27 #include <File.h>
28 #endif
29 
30 void Radeon_ReadSettings( virtual_card *vc )
31 {
32 #ifdef ENABLE_SETTINGS_FILE
33 	BPath path;
34 	int32 tmp;
35 
36 	// per default we enable combine mode;
37 	// if actual mode isn't combine mode, we fall back to clone mode
38 	vc->wanted_multi_mode = mm_combine;
39 	vc->swapDisplays = false;
40 
41 	// per default, show overlay on first port
42 	//vc->whished_overlay_port = 0;
43 
44 	// this is problematic during boot: if there is	multi-user support,
45 	// you don't have a user when app_server gets launched;
46 	// on the other hand, storing settings globally is not user-friendly...
47 	if( find_directory( B_USER_SETTINGS_DIRECTORY, &path ) != B_OK )
48 		return;
49 
50 	path.Append( "radeon" );
51 
52 	BFile file( path.Path(), B_READ_ONLY );
53 
54 	if( file.InitCheck() != B_OK )
55 		return;
56 
57 	BMessage settings;
58 
59 	if( settings.Unflatten( &file ) != B_OK )
60 		return;
61 
62 	if( settings.FindBool( "SwapDisplays", &vc->swapDisplays ) != B_OK )
63 		vc->swapDisplays = false;
64 
65 	if( settings.FindInt32( "MultiMonitorMode", &tmp ) != B_OK )
66 		tmp = mm_combine;
67 
68 	switch( tmp ) {
69 	case mm_none:
70 	case mm_mirror:
71 	case mm_combine:
72 	case mm_clone:
73 		vc->wanted_multi_mode = (multi_mode_e) tmp;
74 		break;
75 	default:
76 		vc->wanted_multi_mode = mm_combine;
77 	}
78 
79 	if( settings.FindInt32( "OverlayPort", &tmp ) != B_OK )
80 		tmp = 0;
81 
82 	//vc->whished_overlay_port = tmp;
83 #else
84 	vc->wanted_multi_mode = mm_combine;
85 	vc->swapDisplays = false;
86 	vc->swapDisplays = false;
87 #endif
88 }
89 
90 void Radeon_WriteSettings( virtual_card *vc )
91 {
92 #ifdef ENABLE_SETTINGS_FILE
93 	BPath path;
94 	int32 tmp;
95 
96 	// this is problematic during boot: if there is	multi-user support,
97 	// you don't have a user when app_server gets launched;
98 	// on the other hand, storing settings globally is not user-friendly...
99 	if( find_directory( B_USER_SETTINGS_DIRECTORY, &path ) != B_OK )
100 		return;
101 
102 	path.Append( "radeon" );
103 
104 	BFile file( path.Path(), B_CREATE_FILE | B_WRITE_ONLY );
105 
106 	if( file.InitCheck() != B_OK )
107 		return;
108 
109 	BMessage settings;
110 
111 	settings.AddBool( "SwapDisplays", vc->swapDisplays );
112 	tmp = vc->wanted_multi_mode;
113 	settings.AddInt32( "MultiMonitorMode", tmp );
114 	/*tmp = vc->whished_overlay_port;
115 	settings.AddInt32( "OverlayPort", tmp );*/
116 
117 	settings.Flatten( &file );
118 #endif
119 }
120