From e48af9e4ec05afdae58e5b8861f3e5eb9efbc478 Mon Sep 17 00:00:00 2001 From: Yourself <0azrune6@zard.anonaddy.com> Date: Wed, 22 Mar 2023 15:11:23 -0400 Subject: [PATCH] Icon-O-Matic: cleanup workspace switching code * Remove comment stating DesktopColor is buggy. The documentation has since been updated clarifying that this is the expected behavior. * Refactor code. * No functional changes. Change-Id: I03711136eb613afb80ad8c03a7f18ba6d15f641c Reviewed-on: https://review.haiku-os.org/c/haiku/+/6256 Tested-by: Automation Reviewed-by: Adrien Destugues --- src/apps/icon-o-matic/MainWindow.cpp | 38 +++++++++++++--------------- src/apps/icon-o-matic/MainWindow.h | 2 ++ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/apps/icon-o-matic/MainWindow.cpp b/src/apps/icon-o-matic/MainWindow.cpp index 70b14b1514..c49607a0c5 100644 --- a/src/apps/icon-o-matic/MainWindow.cpp +++ b/src/apps/icon-o-matic/MainWindow.cpp @@ -575,34 +575,18 @@ MainWindow::WorkspaceActivated(int32 workspace, bool active) { BWindow::WorkspaceActivated(workspace, active); - // NOTE: hack to workaround buggy BScreen::DesktopColor() on R5 - - uint32 workspaces = Workspaces(); - if (!active || ((1 << workspace) & workspaces) == 0) - return; - - WorkspacesChanged(workspaces, workspaces); + if (active) + _WorkspaceEntered(); } void MainWindow::WorkspacesChanged(uint32 oldWorkspaces, uint32 newWorkspaces) { - if (oldWorkspaces != newWorkspaces) - BWindow::WorkspacesChanged(oldWorkspaces, newWorkspaces); + BWindow::WorkspacesChanged(oldWorkspaces, newWorkspaces); - BScreen screen(this); - - // Unfortunately, this is buggy on R5: screen.DesktopColor() - // as well as ui_color(B_DESKTOP_COLOR) return the color - // of the *active* screen, not the one on which this window - // is. So this trick only works when you drag this window - // from another workspace onto the current workspace, not - // when you drag the window from the current workspace onto - // another workspace and then switch to the other workspace. - - fIconPreview32Desktop->SetIconBGColor(screen.DesktopColor()); - fIconPreview64->SetIconBGColor(screen.DesktopColor()); + if((1 << current_workspace() & newWorkspaces) != 0) + _WorkspaceEntered(); } @@ -1274,6 +1258,18 @@ MainWindow::_ImproveScrollBarLayout(BView* target) // #pragma mark - +void +MainWindow::_WorkspaceEntered() +{ + BScreen screen(this); + fIconPreview32Desktop->SetIconBGColor(screen.DesktopColor()); + fIconPreview64->SetIconBGColor(screen.DesktopColor()); +} + + +// #pragma mark - + + bool MainWindow::_CheckSaveIcon(const BMessage* currentMessage) { diff --git a/src/apps/icon-o-matic/MainWindow.h b/src/apps/icon-o-matic/MainWindow.h index 32b8f866cb..95f435f6b2 100644 --- a/src/apps/icon-o-matic/MainWindow.h +++ b/src/apps/icon-o-matic/MainWindow.h @@ -84,6 +84,8 @@ private: void _ImproveScrollBarLayout(BView* target); + void _WorkspaceEntered(); + bool _CheckSaveIcon(const BMessage* currentMessage); void _PickUpActionBeforeSave();