[Haiku-commits] r24280 - haiku/trunk/src/preferences/screen

aldeck at BerliOS aldeck at mail.berlios.de
Thu Mar 6 21:17:20 CET 2008


Author: aldeck
Date: 2008-03-06 21:17:20 +0100 (Thu, 06 Mar 2008)
New Revision: 24280
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=24280&view=rev

Modified:
   haiku/trunk/src/preferences/screen/ScreenWindow.cpp
   haiku/trunk/src/preferences/screen/ScreenWindow.h
Log:
* as discussed on the dev list, fixed revert and apply behaviour (tested 
under vesa and supported mode). Changed message of the vesa warning 
alert. TODO: additional warning text (see discussion)
* apply now stays deactivated if you only change the workspace count as 
it is applied instantly already.
* disabled current workspace menu item for now since it is not 
implemented. see ticket #696


Modified: haiku/trunk/src/preferences/screen/ScreenWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/screen/ScreenWindow.cpp	2008-03-06 20:11:56 UTC (rev 24279)
+++ haiku/trunk/src/preferences/screen/ScreenWindow.cpp	2008-03-06 20:17:20 UTC (rev 24280)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2007, Haiku.
+ * Copyright 2001-2008, Haiku.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -9,6 +9,7 @@
  *		Thomas Kurschel
  *		Axel Dörfler, axeld at pinc-software.de
  *		Stephan Aßmus <superstippi at gmx.de>
+ *		Alexandre Deckner, alex at zappotek.com
  */
 
 
@@ -245,11 +246,15 @@
 	popUpMenu->AddItem(fAllWorkspacesItem);
 	BMenuItem *item = new BMenuItem("Current Workspace",
 		new BMessage(WORKSPACE_CHECK_MSG));
-	if (_IsVesa()) {
+	
+	// TODO: since per workspace settings is unimplemented (Ticket #693)
+	// 		 we force the menu to "All Workspaces" for now
+	//if (_IsVesa()) {
 		fAllWorkspacesItem->SetMarked(true);
 		item->SetEnabled(false);
-	} else
-		item->SetMarked(true);
+	//} else
+	//	item->SetMarked(true);
+		
 	popUpMenu->AddItem(item);
 
 	BMenuField* workspaceMenuField = new BMenuField(BRect(0, 0, 100, 15),
@@ -346,6 +351,8 @@
 
 	float min, max;
 	if (fScreenMode.GetRefreshLimits(fActive, min, max) && min == max) {
+		// TODO: investigate, doesn't work for VESA at least
+		
 		// This is a special case for drivers that only support a single
 		// frequency, like the VESA driver
 		BString name;
@@ -778,8 +785,10 @@
 void
 ScreenWindow::WorkspaceActivated(int32 workspace, bool state)
 {
-	fScreenMode.GetOriginalMode(fOriginal, workspace);
-	UpdateActiveMode();
+	if (!_IsVesa()) {
+		fScreenMode.GetOriginalMode(fOriginal, workspace);
+		UpdateActiveMode();
+	}
 	
 	BMessage message(UPDATE_DESKTOP_COLOR_MSG);
 	PostMessage(&message, fMonitorView);
@@ -935,6 +944,7 @@
 		case BUTTON_REVERT_MSG:
 		{
 			fModified = false;
+			fVesaApplied = false;
 			BMenuItem *item;
 			item = fWorkspaceCountField->Menu()->ItemAt(fOriginalWorkspaceCount - 1);
 			if (item != NULL)
@@ -942,9 +952,17 @@
 
 			// ScreenMode::Revert() assumes that we first set the correct number
 			// of workspaces
-			set_workspace_count(fOriginalWorkspaceCount);
-			fScreenMode.Revert();
-			UpdateActiveMode();
+						
+			if (_IsVesa()) {				
+				set_workspace_count(fOriginalWorkspaceCount);
+				fActive = fOriginal;
+				fSelected = fOriginal;
+				UpdateControls();
+			} else {
+				set_workspace_count(fOriginalWorkspaceCount);
+				fScreenMode.Revert();
+				UpdateActiveMode();
+			}			
 			break;
 		}
 
@@ -996,26 +1014,73 @@
 }
 
 
-bool
-ScreenWindow::CanApply() const
+status_t
+ScreenWindow::_ReadVesaModeFile(screen_mode& mode) const
 {
-	return fAllWorkspacesItem->IsMarked() || fSelected != fActive;
-}
+	BPath path;
+	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
+	if (status < B_OK)
+		return status;
 
+	path.Append("kernel/drivers/vesa");	
+	BFile file;
+	status = file.SetTo(path.Path(), B_READ_ONLY);
+	if (status < B_OK)
+		return status;
 
-bool
-ScreenWindow::CanRevert() const
-{
-	return fSelected != fActive || count_workspaces() != fOriginalWorkspaceCount
-		|| fModified;
+	char buffer[256];
+	
+	ssize_t bytesRead = file.Read(buffer, sizeof(buffer) - 1);
+	if (bytesRead < B_OK) {
+		return bytesRead;
+	} else {
+		buffer[bytesRead] = '\0';	
+	}
+	
+	char ignore[256];
+		// if the file is malformed, sscanf shouldn't crash
+		// on reading a big string since we don't even read
+		// as much from the file
+	uint32 bitDepth = 0;
+	
+	if (sscanf(buffer, "%s %ld %ld %ld", ignore,
+		&mode.width, &mode.height, &bitDepth) == 4) {
+		
+		//TODO: check for valid width and height values
+			
+		switch (bitDepth) {
+			case 32:
+				mode.space = B_RGB32;
+				break;
+			case 24:
+				mode.space = B_RGB24;
+				break;
+			case 16:
+				mode.space = B_RGB16;
+				break;
+			case 15:
+				mode.space = B_RGB15;
+				break;
+			case 8:
+				mode.space = B_CMAP8;
+				break;
+			default:
+				// invalid value, we force it to B_RGB16 just in case
+				mode.space = B_RGB16;
+				return B_ERROR;			
+		}		
+		return B_OK;
+	} else {
+		return B_ERROR;
+	}
 }
 
 
 void
 ScreenWindow::CheckApplyEnabled()
 {
-	fApplyButton->SetEnabled(CanApply());
-	fRevertButton->SetEnabled(CanRevert());
+	fApplyButton->SetEnabled(fSelected != fActive);
+	fRevertButton->SetEnabled(count_workspaces() != fOriginalWorkspaceCount || fSelected != fOriginal);
 }
 
 
@@ -1024,6 +1089,12 @@
 {
 	fOriginalWorkspaceCount = count_workspaces();
 	fScreenMode.Get(fOriginal);
+	
+	// If we are in vesa we overwrite fOriginal's resolution and bitdepth
+	// with those found the vesa settings file. (if the file exists)
+	if (_IsVesa())
+		_ReadVesaModeFile(fOriginal);
+
 	fScreenMode.UpdateOriginalModes();
 }
 
@@ -1033,12 +1104,13 @@
 {
 	if (_IsVesa()) {
 		(new BAlert("VesaAlert",
-			"Your graphics card is not supported. Resolution changes will be "
-			"adopted on next system startup.\n", "Okay", NULL, NULL, B_WIDTH_AS_USUAL,
+			"Haiku is using your video card in safe mode (VESA)."
+			" Your settings will be applied on next startup.\n", "Okay", NULL, NULL, B_WIDTH_AS_USUAL,			
 			B_INFO_ALERT))->Go(NULL);
 
 		fVesaApplied = true;
 		fActive = fSelected;
+		UpdateControls();		
 		return;
 	}
 	

Modified: haiku/trunk/src/preferences/screen/ScreenWindow.h
===================================================================
--- haiku/trunk/src/preferences/screen/ScreenWindow.h	2008-03-06 20:11:56 UTC (rev 24279)
+++ haiku/trunk/src/preferences/screen/ScreenWindow.h	2008-03-06 20:17:20 UTC (rev 24280)
@@ -50,10 +50,8 @@
 
 		void Apply();
 
-		bool CanApply() const;
-		bool CanRevert() const;
-
 		status_t _WriteVesaModeFile(const screen_mode& mode) const;
+		status_t _ReadVesaModeFile(screen_mode& mode) const;		
 		bool _IsVesa() const { return fIsVesa; }
 
 		void LayoutControls(uint32 flags);




More information about the Haiku-commits mailing list