[haiku-commits] r37816 - haiku/trunk/src/servers/app

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 30 Jul 2010 03:19:20 +0200 (CEST)

Author: czeidler
Date: 2010-07-30 03:19:20 +0200 (Fri, 30 Jul 2010)
New Revision: 37816
Changeset: http://dev.haiku-os.org/changeset/37816

Modified:
   haiku/trunk/src/servers/app/DecorManager.cpp
   haiku/trunk/src/servers/app/DecorManager.h
   haiku/trunk/src/servers/app/Desktop.cpp
   haiku/trunk/src/servers/app/Desktop.h
Log:
-Make Windows private again and lock the iteration over the windows when 
reloading the decorators.
- Make the used decorator persistent.



Modified: haiku/trunk/src/servers/app/DecorManager.cpp
===================================================================
--- haiku/trunk/src/servers/app/DecorManager.cpp        2010-07-29 20:37:45 UTC 
(rev 37815)
+++ haiku/trunk/src/servers/app/DecorManager.cpp        2010-07-30 01:19:20 UTC 
(rev 37816)
@@ -12,6 +12,7 @@
 #include <Directory.h>
 #include <Entry.h>
 #include <File.h>
+#include <FindDirectory.h>
 #include <Message.h>
 #include <Path.h>
 #include <Rect.h>
@@ -122,24 +123,9 @@
 
        // Add any on disk
        RescanDecorators();
-#if 0
 
-       // Find out which one should be the active one
-       BDirectory dir;
-       if (dir.SetTo(SERVER_SETTINGS_DIR) == B_ENTRY_NOT_FOUND)
-               create_directory(SERVER_SETTINGS_DIR, 0777);
+       _LoadSettingsFromDisk();
 
-       BMessage settings;
-       BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY);
-
-       // Fallback to the default decorator if something goes wrong
-       if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) {
-               BString itemtext;
-               if (settings.FindString("decorator", &itemtext) == B_OK) {
-                       fCurrentDecor = _FindDecor(itemtext.String());
-               }
-       }
-#endif
        if (!fCurrentDecor)
                fCurrentDecor = (DecorInfo*)fDecorList.ItemAt(0L);
 }
@@ -239,7 +225,8 @@
 
        if (newDecInfo) {
                fCurrentDecor = newDecInfo;
-               _UpdateWindows(desktop);
+               desktop->ReloadAllDecorators();
+               _SaveSettingsToDisk();
                return true;
        }
 
@@ -311,12 +298,65 @@
 }
 
 
-void
-DecorManager::_UpdateWindows(Desktop* desktop)
+static const char* kSettingsDir = "system/app_server";
+static const char* kSettingsFile = "decorator_settings";
+
+
+bool
+DecorManager::_LoadSettingsFromDisk()
 {
-       for (int32 i = 0; i < kMaxWorkspaces; i++) {
-               for (Window* window = desktop->Windows(i).LastWindow(); window;
-                               window = window->PreviousWindow(i))
-                       desktop->ReloadDecorator(window);
+       // get the user settings directory
+       BPath path;
+       status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
+       if (error != B_OK)
+               return false;
+
+       path.Append(kSettingsDir);
+       path.Append(kSettingsFile);
+       BFile file(path.Path(), B_READ_ONLY);
+       if (file.InitCheck() != B_OK)
+               return false;
+
+       BMessage settings;
+       if (settings.Unflatten(&file) == B_OK) {
+               BString itemtext;
+               if (settings.FindString("decorator", &itemtext) == B_OK) {
+                       DecorInfo* decor = _FindDecor(itemtext.String());
+                       if (decor) {
+                               fCurrentDecor = decor;
+                               return true;
+                       }
+               }
        }
+
+       return false;
 }
+
+
+bool
+DecorManager::_SaveSettingsToDisk()
+{
+       // get the user settings directory
+       BPath path;
+       status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
+       if (error != B_OK)
+               return false;
+
+       path.Append(kSettingsDir);
+       if (create_directory(path.Path(), 777) != B_OK)
+               return false;
+
+       path.Append(kSettingsFile);
+       BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
+       if (file.InitCheck() != B_OK)
+               return false;
+
+       BMessage settings;
+       if (settings.AddString("decorator", fCurrentDecor->Name()) != B_OK)
+               return false;
+       if (settings.Flatten(&file) != B_OK)
+               return false;
+
+       return true;
+}
+

Modified: haiku/trunk/src/servers/app/DecorManager.h
===================================================================
--- haiku/trunk/src/servers/app/DecorManager.h  2010-07-29 20:37:45 UTC (rev 
37815)
+++ haiku/trunk/src/servers/app/DecorManager.h  2010-07-30 01:19:20 UTC (rev 
37816)
@@ -50,7 +50,8 @@
                void            _EmptyList();
                DecorInfo*      _FindDecor(const char *name);
 
-               void            _UpdateWindows(Desktop* desktop);
+               bool            _LoadSettingsFromDisk();
+               bool            _SaveSettingsToDisk();
 
                BObjectList<DecorInfo> fDecorList;
                DecorInfo*      fCurrentDecor;

Modified: haiku/trunk/src/servers/app/Desktop.cpp
===================================================================
--- haiku/trunk/src/servers/app/Desktop.cpp     2010-07-29 20:37:45 UTC (rev 
37815)
+++ haiku/trunk/src/servers/app/Desktop.cpp     2010-07-30 01:19:20 UTC (rev 
37816)
@@ -394,7 +394,7 @@
        fSettings = new DesktopSettingsPrivate(fServerReadOnlyMemory);
 
        for (int32 i = 0; i < kMaxWorkspaces; i++) {
-               Windows(i).SetIndex(i);
+               _Windows(i).SetIndex(i);
                
fWorkspaces[i].RestoreConfiguration(*fSettings->WorkspacesMessage(i));
        }
 
@@ -1519,7 +1519,7 @@
                if (i == fCurrentWorkspace && window->IsVisible())
                        visibleBefore = window->VisibleRegion();
 
-               Window* backmost = window->Backmost(Windows(i).LastWindow(), i);
+               Window* backmost = window->Backmost(_Windows(i).LastWindow(), 
i);
                if (backmost != NULL) {
                        // check if the backmost window is really behind it
                        Window* previous = window->PreviousWindow(i);
@@ -1532,13 +1532,13 @@
 
                        if (previous == NULL) {
                                // need to reinsert window before its backmost 
window
-                               Windows(i).RemoveWindow(window);
-                               Windows(i).AddWindow(window, 
backmost->NextWindow(i));
+                               _Windows(i).RemoveWindow(window);
+                               _Windows(i).AddWindow(window, 
backmost->NextWindow(i));
                                changed = true;
                        }
                }
 
-               Window* frontmost = window->Frontmost(Windows(i).FirstWindow(), 
i);
+               Window* frontmost = 
window->Frontmost(_Windows(i).FirstWindow(), i);
                if (frontmost != NULL) {
                        // check if the frontmost window is really in front of 
it
                        Window* next = window->NextWindow(i);
@@ -1551,8 +1551,8 @@
 
                        if (next == NULL) {
                                // need to reinsert window behind its frontmost 
window
-                               Windows(i).RemoveWindow(window);
-                               Windows(i).AddWindow(window, frontmost);
+                               _Windows(i).RemoveWindow(window);
+                               _Windows(i).AddWindow(window, frontmost);
                                changed = true;
                        }
                }
@@ -1901,20 +1901,25 @@
 
 
 void
-Desktop::ReloadDecorator(Window* window)
+Desktop::ReloadAllDecorators()
 {
        AutoWriteLocker _(fWindowLock);
 
-       BRegion oldBorder;
-       window->GetBorderRegion(&oldBorder);
+       for (int32 i = 0; i < kMaxWorkspaces; i++) {
+               for (Window* window = _Windows(i).LastWindow(); window;
+                               window = window->PreviousWindow(i)) {
+                       BRegion oldBorder;
+                       window->GetBorderRegion(&oldBorder);
 
-       window->ReloadDecorator();
+                       window->ReloadDecorator();
 
-       BRegion border;
-       window->GetBorderRegion(&border);
+                       BRegion border;
+                       window->GetBorderRegion(&border);
 
-       border.Include(&oldBorder);
-       _RebuildAndRedrawAfterWindowChange(window, border);
+                       border.Include(&oldBorder);
+                       _RebuildAndRedrawAfterWindowChange(window, border);
+               }
+       }
 }
 
 
@@ -2087,14 +2092,14 @@
                return;
        }
 
-       int32 count = Windows(workspace).Count();
+       int32 count = _Windows(workspace).Count();
 
        // write list
 
        sender.StartMessage(B_OK);
        sender.Attach<int32>(count);
 
-       for (Window *window = Windows(workspace).LastWindow(); window != NULL;
+       for (Window *window = _Windows(workspace).LastWindow(); window != NULL;
                        window = window->PreviousWindow(workspace)) {
                sender.Attach<int32>(window->ServerWindow()->ServerToken());
        }
@@ -2137,7 +2142,7 @@
 
        int32 count = 0;
 
-       for (Window *window = Windows(workspace).LastWindow(); window != NULL;
+       for (Window *window = _Windows(workspace).LastWindow(); window != NULL;
                        window = window->PreviousWindow(workspace)) {
                team_id team = window->ServerWindow()->ClientTeam();
                if (count > 1) {
@@ -2446,7 +2451,7 @@
 
 
 WindowList&
-Desktop::Windows(int32 index)
+Desktop::_Windows(int32 index)
 {
        return fWorkspaces[index].Windows();
 }
@@ -2471,18 +2476,18 @@
                if (fFront != NULL && fFront->IsNormal()
                        && floating->HasInSubset(fFront)) {
                        // is now visible
-                       if (Windows(previousWorkspace).HasWindow(floating)
+                       if (_Windows(previousWorkspace).HasWindow(floating)
                                && previousWorkspace != nextWorkspace
                                && 
!floating->InSubsetWorkspace(previousWorkspace)) {
                                // but no longer on the previous workspace
-                               
Windows(previousWorkspace).RemoveWindow(floating);
+                               
_Windows(previousWorkspace).RemoveWindow(floating);
                                floating->SetCurrentWorkspace(-1);
                        }
 
-                       if (!Windows(nextWorkspace).HasWindow(floating)) {
+                       if (!_Windows(nextWorkspace).HasWindow(floating)) {
                                // but wasn't before
-                               Windows(nextWorkspace).AddWindow(floating,
-                                       
floating->Frontmost(Windows(nextWorkspace).FirstWindow(),
+                               _Windows(nextWorkspace).AddWindow(floating,
+                                       
floating->Frontmost(_Windows(nextWorkspace).FirstWindow(),
                                        nextWorkspace));
                                floating->SetCurrentWorkspace(nextWorkspace);
                                if (mouseEventWindow != fFront)
@@ -2491,11 +2496,11 @@
                                // TODO: put the floating last in the floating 
window list to
                                // preserve the on screen window order
                        }
-               } else if (Windows(previousWorkspace).HasWindow(floating)
+               } else if (_Windows(previousWorkspace).HasWindow(floating)
                        && !floating->InSubsetWorkspace(previousWorkspace)) {
                        // was visible, but is no longer
 
-                       Windows(previousWorkspace).RemoveWindow(floating);
+                       _Windows(previousWorkspace).RemoveWindow(floating);
                        floating->SetCurrentWorkspace(-1);
                        _HideWindow(floating);
 
@@ -2729,7 +2734,7 @@
                if (workspace_in_workspaces(i, oldWorkspaces)) {
                        // window is on this workspace, is it anymore?
                        if (!workspace_in_workspaces(i, newWorkspaces)) {
-                               Windows(i).RemoveWindow(window);
+                               _Windows(i).RemoveWindow(window);
                                if (fLastWorkspaceFocus[i] == window)
                                        fLastWorkspaceFocus[i] = NULL;
 
@@ -2744,8 +2749,8 @@
                } else {
                        // window was not on this workspace, is it now?
                        if (workspace_in_workspaces(i, newWorkspaces)) {
-                               Windows(i).AddWindow(window,
-                                       
window->Frontmost(Windows(i).FirstWindow(), i));
+                               _Windows(i).AddWindow(window,
+                                       
window->Frontmost(_Windows(i).FirstWindow(), i));
 
                                if (i == CurrentWorkspace()) {
                                        // make the window visible in current 
workspace
@@ -3174,9 +3179,9 @@
                                // But only normal windows are following
                                uint32 oldWorkspaces = 
movedWindow->Workspaces();
 
-                               
Windows(previousIndex).RemoveWindow(movedWindow);
-                               Windows(index).AddWindow(movedWindow,
-                                       
movedWindow->Frontmost(Windows(index).FirstWindow(),
+                               
_Windows(previousIndex).RemoveWindow(movedWindow);
+                               _Windows(index).AddWindow(movedWindow,
+                                       
movedWindow->Frontmost(_Windows(index).FirstWindow(),
                                        index));
 
                                // TODO: subset windows will always flicker 
this way
@@ -3189,9 +3194,9 @@
                                InvokeSetWindowWorkspaces(movedWindow, 
movedWindow->Workspaces());
                        } else {
                                // make sure it's frontmost
-                               Windows(index).RemoveWindow(movedWindow);
-                               Windows(index).AddWindow(movedWindow,
-                                       
movedWindow->Frontmost(Windows(index).FirstWindow(),
+                               _Windows(index).RemoveWindow(movedWindow);
+                               _Windows(index).AddWindow(movedWindow,
+                                       
movedWindow->Frontmost(_Windows(index).FirstWindow(),
                                        index));
                        }
                }
@@ -3242,7 +3247,7 @@
        WindowList windows(kWorkingList);
        BList previousRegions;
 
-       for (Window* window = Windows(index).FirstWindow();
+       for (Window* window = _Windows(index).FirstWindow();
                        window != NULL; window = window->NextWindow(index)) {
                BPoint position = window->Anchor(index).position;
 
@@ -3296,7 +3301,7 @@
        _RebuildClippingForAllWindows(stillAvailableOnScreen);
        _SetBackground(stillAvailableOnScreen);
 
-       for (Window* window = Windows(index).FirstWindow(); window != NULL;
+       for (Window* window = _Windows(index).FirstWindow(); window != NULL;
                        window = window->NextWindow(index)) {
                // send B_WORKSPACE_ACTIVATED message
                window->WorkspaceActivated(index, true);
@@ -3332,7 +3337,7 @@
        // Set new focus, but keep focus to a floating window if still visible
        if (movedWindow != NULL)
                SetFocusWindow(movedWindow);
-       else if (!Windows(index).HasWindow(FocusWindow())
+       else if (!_Windows(index).HasWindow(FocusWindow())
                || (FocusWindow() != NULL && !FocusWindow()->IsFloating()))
                SetFocusWindow(fLastWorkspaceFocus[index]);
 

Modified: haiku/trunk/src/servers/app/Desktop.h
===================================================================
--- haiku/trunk/src/servers/app/Desktop.h       2010-07-29 20:37:45 UTC (rev 
37815)
+++ haiku/trunk/src/servers/app/Desktop.h       2010-07-30 01:19:20 UTC (rev 
37816)
@@ -233,7 +233,7 @@
                        void                            Redraw();
                        void                            RedrawBackground();
 
-                       void                            ReloadDecorator(Window* 
window);
+                       void                            ReloadAllDecorators();
 
                        BRegion&                        BackgroundRegion()
                                                                        { 
return fBackgroundRegion; }
@@ -252,9 +252,10 @@
                                                                        
BPrivate::LinkSender& sender);
 
                        WindowList&                     CurrentWindows();
-                       WindowList&                     Windows(int32 index);
 
 private:
+                       WindowList&                     _Windows(int32 index);
+
                        void                            _LaunchInputServer();
                        void                            _GetLooperName(char* 
name, size_t size);
                        void                            _PrepareQuit();


Other related posts:

  • » [haiku-commits] r37816 - haiku/trunk/src/servers/app - clemens . zeidler