added 5 changesets to branch 'refs/remotes/axeld-github/background' old head: 0000000000000000000000000000000000000000 new head: af954b5cb2f3e9585dc4f2227f2612aaa66cf542 overview: https://github.com/axeld/haiku/compare/af954b5 ---------------------------------------------------------------------------- 3227d09: Minor cleanup. c4d6082: app_server: The Workspace class now stores bitmap info, too. 229d6dc: BScreen: implemented getting/setting the workspace bitmap. * Added new bitmap options to InterfaceDefs.h -- the plan is to make those work with view bitmaps as well. * The server side is not yet implemented. 92462fb: app_server: implemented server side AS_{GET|SET}_DESKTOP_IMAGE. * The image isn't yet drawn, though. af954b5: app_server: actually draw the desktop bitmap. * The drawing is currently very limited, and will just draw the bitmap to fill the screen completely. * Added short test tool to set a background directly in the app_server. * Furthermore, acquiring a bitmap is obviously no guarantee that its buffer will stay in memory; the client memory allocator must not be destroyed as long as its memory is in use. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 14 files changed, 560 insertions(+), 39 deletions(-) build/jam/HaikuImage | 6 +- headers/os/interface/InterfaceDefs.h | 9 +- headers/os/interface/Screen.h | 33 +++++-- headers/private/app/ServerProtocol.h | 5 +- headers/private/interface/PrivateScreen.h | 24 ++++- src/bin/Jamfile | 1 + src/bin/setbackground.cpp | 33 +++++++ src/kits/interface/PrivateScreen.cpp | 116 +++++++++++++++++++++++- src/kits/interface/Screen.cpp | 126 ++++++++++++++++++++++++-- src/servers/app/Desktop.cpp | 33 ++++++- src/servers/app/ServerApp.cpp | 70 ++++++++++++++ src/servers/app/Workspace.cpp | 92 ++++++++++++++++++- src/servers/app/Workspace.h | 23 +++-- src/servers/app/WorkspacePrivate.h | 28 +++++- ############################################################################ Commit: 3227d096c7667272ab4fae830215beafc2013be8 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Feb 28 22:31:52 2013 UTC Minor cleanup. ---------------------------------------------------------------------------- diff --git a/src/servers/app/Workspace.h b/src/servers/app/Workspace.h index 7e0bfe9..e92db6c 100644 --- a/src/servers/app/Workspace.h +++ b/src/servers/app/Workspace.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2009, Haiku. + * Copyright 2005-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -15,11 +15,11 @@ class Desktop; class Window; -/*! -Workspace objects are intended to be short-lived. You create them while -already holding a lock to the Desktop read-write lock and then you can use them -to query information, and then you destroy them again, for example by letting -them go out of scope. + +/*! Workspace objects are intended to be short-lived. You create them while + already holding a lock to the Desktop read-write lock and then you can use + them to query information, and then you destroy them again, for example by + letting them go out of scope. */ class Workspace { public: @@ -48,4 +48,5 @@ private: bool fCurrentWorkspace; }; + #endif /* WORKSPACE_H */ ############################################################################ Commit: c4d60828bce93703a996f519eccd0e568de42358 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Feb 28 22:56:50 2013 UTC app_server: The Workspace class now stores bitmap info, too. ---------------------------------------------------------------------------- diff --git a/src/servers/app/Workspace.cpp b/src/servers/app/Workspace.cpp index 1b890dd..8f9a2d9 100644 --- a/src/servers/app/Workspace.cpp +++ b/src/servers/app/Workspace.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2005-2009, Haiku. + * Copyright 2005-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -48,12 +48,31 @@ Workspace::Private::SetColor(const rgb_color& color) void +Workspace::Private::SetImage(const char* path, ServerBitmap* bitmap, + uint32 options, const BPoint& offset) +{ + fImagePath = path; + fBitmap = bitmap; + fBitmapOptions = options; + fBitmapOffset = offset; +} + + +void Workspace::Private::RestoreConfiguration(const BMessage& settings) { rgb_color color; - if (settings.FindInt32("color", (int32 *)&color) == B_OK) + if (settings.FindInt32("color", (int32*)&color) == B_OK) fColor = color; + fImagePath = settings.GetString("imagePath", NULL); + fBitmapOptions = settings.GetInt32("bitmapOptions", 0); + fBitmapOffset = settings.GetPoint("bitmapOffset", BPoint(0, 0)); + + fStoredImagePath = fImagePath; + fStoredBitmapOptions = fBitmapOptions; + fStoredBitmapOffset = fBitmapOffset; + fStoredScreenConfiguration.Restore(settings); fCurrentScreenConfiguration.Restore(settings); } @@ -65,7 +84,18 @@ void Workspace::Private::StoreConfiguration(BMessage& settings) { fStoredScreenConfiguration.Store(settings); - settings.AddInt32("color", *(int32 *)&fColor); + + settings.SetInt32("color", *(int32*)&fColor); + + if (!fImagePath.IsEmpty()) { + settings.SetString("imagePath", fImagePath); + settings.SetInt32("bitmapOptions", BitmapOptions()); + settings.SetPoint("bitmapOffset", BitmapOffset()); + } + + fStoredImagePath = fImagePath; + fStoredBitmapOptions = fBitmapOptions; + fStoredBitmapOffset = fBitmapOffset; } @@ -106,7 +136,7 @@ Workspace::Color() const void Workspace::SetColor(const rgb_color& color, bool makeDefault) { - if (color == Color()) + if (color == Color() && (!makeDefault || color == fWorkspace.StoredColor())) return; fWorkspace.SetColor(color); @@ -116,6 +146,51 @@ Workspace::SetColor(const rgb_color& color, bool makeDefault) } +const char* +Workspace::ImagePath() const +{ + return fWorkspace.ImagePath().String(); +} + +ServerBitmap* +Workspace::Bitmap() const +{ + return fWorkspace.Bitmap(); +} + + +uint32 +Workspace::BitmapOptions() const +{ + return fWorkspace.BitmapOptions(); +} + + +const BPoint& +Workspace::BitmapOffset() const +{ + return fWorkspace.BitmapOffset(); +} + + +void +Workspace::SetImage(const char* path, ServerBitmap* bitmap, uint32 options, + const BPoint& offset, bool makeDefault) +{ + if ((fWorkspace.ImagePath() == path && bitmap == Bitmap() + && options == BitmapOptions() && offset == BitmapOffset()) + && (!makeDefault || (fWorkspace.StoredImagePath() == path + && options == fWorkspace.StoredBitmapOptions() + && offset == fWorkspace.StoredBitmapOffset()))) + return; + + fWorkspace.SetImage(path, bitmap, options, offset); + fDesktop.RedrawBackground(); + if (makeDefault) + fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index()); +} + + status_t Workspace::GetNextWindow(Window*& _window, BPoint& _leftTop) { diff --git a/src/servers/app/Workspace.h b/src/servers/app/Workspace.h index e92db6c..00ed672 100644 --- a/src/servers/app/Workspace.h +++ b/src/servers/app/Workspace.h @@ -13,6 +13,7 @@ class Desktop; +class ServerBitmap; class Window; @@ -30,6 +31,15 @@ public: const rgb_color& Color() const; void SetColor(const rgb_color& color, bool makeDefault); + + const char* ImagePath() const; + ServerBitmap* Bitmap() const; + uint32 BitmapOptions() const; + const BPoint& BitmapOffset() const; + void SetImage(const char* path, + ServerBitmap* bitmap, uint32 options, + const BPoint& offset, bool makeDefault); + bool IsCurrent() const { return fCurrentWorkspace; } diff --git a/src/servers/app/WorkspacePrivate.h b/src/servers/app/WorkspacePrivate.h index 98b26a1..ecbaea9 100644 --- a/src/servers/app/WorkspacePrivate.h +++ b/src/servers/app/WorkspacePrivate.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2009, Haiku. + * Copyright 2005-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -47,6 +47,21 @@ public: const rgb_color& Color() const { return fColor; } void SetColor(const rgb_color& color); + const BString& ImagePath() const { return fImagePath; } + ServerBitmap* Bitmap() const { return fBitmap; } + uint32 BitmapOptions() const { return fBitmapOptions; } + const BPoint& BitmapOffset() const { return fBitmapOffset; } + void SetImage(const char* path, + ServerBitmap* bitmap, uint32 options, + const BPoint& offset); + + const rgb_color& StoredColor() const { return fStoredColor; } + const BString& StoredImagePath() const + { return fStoredImagePath; } + uint32 StoredBitmapOptions() const + { return fStoredBitmapOptions; } + const BPoint& StoredBitmapOffset() const + { return fStoredBitmapOffset; } ScreenConfigurations& CurrentScreenConfiguration() { return fCurrentScreenConfiguration; } @@ -65,7 +80,18 @@ private: ScreenConfigurations fStoredScreenConfiguration; ScreenConfigurations fCurrentScreenConfiguration; + rgb_color fColor; + BString fImagePath; + ServerBitmap* fBitmap; + uint32 fBitmapOptions; + BPoint fBitmapOffset; + + rgb_color fStoredColor; + BString fStoredImagePath; + uint32 fStoredBitmapOptions; + BPoint fStoredBitmapOffset; }; + #endif /* WORKSPACE_PRIVATE_H */ ############################################################################ Commit: 229d6dc3e6b826ec0086b3152593b14976f22cc1 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Feb 28 23:49:44 2013 UTC BScreen: implemented getting/setting the workspace bitmap. * Added new bitmap options to InterfaceDefs.h -- the plan is to make those work with view bitmaps as well. * The server side is not yet implemented. ---------------------------------------------------------------------------- diff --git a/headers/os/interface/InterfaceDefs.h b/headers/os/interface/InterfaceDefs.h index 51b5f6f..60145a6 100644 --- a/headers/os/interface/InterfaceDefs.h +++ b/headers/os/interface/InterfaceDefs.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008, Haiku, Inc. All rights reserved. + * Copyright 2001-2013, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _INTERFACE_DEFS_H @@ -276,6 +276,12 @@ enum overlay_options { B_OVERLAY_TRANSFER_CHANNEL = 0x00080000 }; +enum view_bitmap_options { + B_VIEW_BITMAP_AT_OFFSET = 0x00001000, + B_VIEW_BITMAP_CENTERED = 0x00002000, + B_VIEW_BITMAP_SCALED_TO_FIT = 0x00004000, +}; + enum bitmap_drawing_options { B_FILTER_BITMAP_BILINEAR = 0x00000100, @@ -425,4 +431,5 @@ extern "C" status_t _init_interface_kit_(); // for convenience, should be removed including the friend declarations // in Menu.h, ... + #endif // _INTERFACE_DEFS_H diff --git a/headers/os/interface/Screen.h b/headers/os/interface/Screen.h index b1479d9..9487b74 100644 --- a/headers/os/interface/Screen.h +++ b/headers/os/interface/Screen.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Haiku, Inc. All rights reserved. + * Copyright 2007-2013, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _SCREEN_H @@ -21,7 +21,7 @@ namespace BPrivate { class BScreen { -public: +public: BScreen(screen_id id = B_MAIN_SCREEN_ID); BScreen(BWindow* window); ~BScreen(); @@ -53,10 +53,30 @@ public: rgb_color DesktopColor(); rgb_color DesktopColor(uint32 workspace); - void SetDesktopColor(rgb_color color, - bool stick = true); - void SetDesktopColor(rgb_color color, - uint32 workspace, bool stick = true); + status_t SetDesktopColor(rgb_color color, + bool makeDefault = true); + status_t SetDesktopColor(rgb_color color, + uint32 workspace, bool makeDefault = true); + + const char* DesktopImage() const; + const char* DesktopImage(uint32 workspace) const; + BPoint DesktopImageOffset() const; + BPoint DesktopImageOffset(uint32 workspace) const; + uint32 DesktopImageOptions() const; + uint32 DesktopImageOptions(uint32 workspace) const; + status_t SetDesktopBitmap(BBitmap* bitmap, + uint32 options, BPoint offset = BPoint()); + status_t SetDesktopBitmap(uint32 workspace, + BBitmap* bitmap, uint32 options, + BPoint offset = BPoint()); + status_t SetDesktopImage(const char* path, + BBitmap* bitmap, uint32 options, + BPoint offset = BPoint(), + bool makeDefault = true); + status_t SetDesktopImage(uint32 workspace, + const char* path, BBitmap* bitmap, + uint32 options, BPoint offset = BPoint(), + bool makeDefault = true); status_t ProposeMode(display_mode* target, const display_mode* low, @@ -105,4 +125,5 @@ BScreen::IndexForColor(rgb_color color) return IndexForColor(color.red, color.green, color.blue, color.alpha); } + #endif // _SCREEN_H diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index ca6c19a..8f7017b 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2012, Haiku. + * Copyright 2001-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -163,6 +163,8 @@ enum { AS_SCREEN_GET_COLORMAP, AS_GET_DESKTOP_COLOR, AS_SET_DESKTOP_COLOR, + AS_GET_DESKTOP_IMAGE, + AS_SET_DESKTOP_IMAGE, AS_GET_SCREEN_ID_FROM_WINDOW, AS_READ_BITMAP, @@ -358,4 +360,5 @@ enum { kNewAllocatorArea = 0x8, }; + #endif // APP_SERVER_PROTOCOL_H diff --git a/headers/private/interface/PrivateScreen.h b/headers/private/interface/PrivateScreen.h index d3e64ef..602837a 100644 --- a/headers/private/interface/PrivateScreen.h +++ b/headers/private/interface/PrivateScreen.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku Inc. + * Copyright 2002-2013, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -27,6 +27,10 @@ class BWindow; namespace BPrivate { + +struct desktop_image_config; + + class BPrivateScreen { public: // Constructor and destructor are private. Use the static methods @@ -58,8 +62,18 @@ public: status_t ReadBitmap(BBitmap* bitmap, bool drawCursor, BRect* bounds); - rgb_color DesktopColor(uint32 index); - void SetDesktopColor(rgb_color, uint32, bool); + rgb_color DesktopColor(uint32 workspace); + status_t SetDesktopColor(rgb_color color, + uint32 workspace, bool makeDefault); + + BBitmap* DesktopBitmap(uint32 workspace); + const char* DesktopImage(uint32 workspace); + BPoint DesktopImageOffset(uint32 workspace); + uint32 DesktopImageOptions(uint32 workspace); + status_t SetDesktopImage(uint32 workspace, + const char* path, BBitmap* bitmap, + uint32 options, BPoint offset, + bool makeDefault); status_t ProposeMode(display_mode* target, const display_mode* low, @@ -97,6 +111,8 @@ private: sem_id _RetraceSemaphore(); status_t _GetFrameBufferConfig( frame_buffer_config& config); + status_t _GetDesktopImage(uint32 workspace, + desktop_image_config& config); static BPrivateScreen* _Get(int32 id, bool check); static bool _IsValid(int32 id); @@ -112,6 +128,8 @@ private: bigtime_t fLastUpdate; }; + } // namespace BPrivate + #endif // _PRIVATE_SCREEN_H_ diff --git a/src/kits/interface/PrivateScreen.cpp b/src/kits/interface/PrivateScreen.cpp index 03610b5..36e0425 100644 --- a/src/kits/interface/PrivateScreen.cpp +++ b/src/kits/interface/PrivateScreen.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009, Haiku Inc. + * Copyright 2002-2013, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -24,6 +24,7 @@ #include <Bitmap.h> #include <Locker.h> #include <ObjectList.h> +#include <String.h> #include <Window.h> #include <AutoLocker.h> @@ -85,6 +86,20 @@ Screens* Screens::sDefaultInstance = NULL; } // unnamed namespace +namespace BPrivate { + + +struct desktop_image_config { + BString path; + BPoint offset; + uint32 options; + int32 bitmap_id; +}; + + +// #pragma mark - + + BPrivateScreen* BPrivateScreen::Get(BWindow* window) { @@ -418,15 +433,14 @@ BPrivateScreen::DesktopColor(uint32 workspace) link.Attach<uint32>(workspace); int32 code; - if (link.FlushWithReply(code) == B_OK - && code == B_OK) + if (link.FlushWithReply(code) == B_OK && code == B_OK) link.Read<rgb_color>(&color); return color; } -void +status_t BPrivateScreen::SetDesktopColor(rgb_color color, uint32 workspace, bool makeDefault) { @@ -436,7 +450,75 @@ BPrivateScreen::SetDesktopColor(rgb_color color, uint32 workspace, link.Attach<rgb_color>(color); link.Attach<uint32>(workspace); link.Attach<bool>(makeDefault); - link.Flush(); + return link.Flush(); +} + + +BBitmap* +BPrivateScreen::DesktopBitmap(uint32 workspace) +{ + desktop_image_config config; + if (_GetDesktopImage(workspace, config) != B_OK) + return NULL; + + // TODO: get bitmap pointer, we only have the ID here; we might need to + // clone the bitmap, first + return NULL; +} + + +const char* +BPrivateScreen::DesktopImage(uint32 workspace) +{ + desktop_image_config config; + if (_GetDesktopImage(workspace, config) != B_OK) + return NULL; + + return config.path.String(); +} + + +BPoint +BPrivateScreen::DesktopImageOffset(uint32 workspace) +{ + desktop_image_config config; + if (_GetDesktopImage(workspace, config) != B_OK) + return BPoint(); + + return config.offset; +} + + +uint32 +BPrivateScreen::DesktopImageOptions(uint32 workspace) +{ + desktop_image_config config; + if (_GetDesktopImage(workspace, config) != B_OK) + return 0; + + return config.options; +} + + +status_t +BPrivateScreen::SetDesktopImage(uint32 workspace, const char* path, + BBitmap* bitmap, uint32 options, BPoint offset, bool makeDefault) +{ + BPrivate::AppServerLink link; + link.StartMessage(AS_SET_DESKTOP_IMAGE); + link.Attach<int32>(workspace); + link.Attach<uint32>(options); + link.Attach<BPoint>(offset); + link.Attach<int32>(bitmap != NULL ? bitmap->fServerToken : 0); + link.Attach<bool>(makeDefault); + link.AttachString(path); + + status_t result; + status_t status = link.FlushWithReply(result); + if (status != B_OK) + return status; + + return result; } @@ -755,6 +837,27 @@ BPrivateScreen::_GetFrameBufferConfig(frame_buffer_config& config) } +status_t +BPrivateScreen::_GetDesktopImage(uint32 workspace, desktop_image_config& config) +{ + BPrivate::AppServerLink link; + link.StartMessage(AS_GET_DESKTOP_IMAGE); + link.Attach<uint32>(workspace); + + int32 code; + status_t status = link.FlushWithReply(code); + if (status != B_OK) + return status; + if (code != B_OK) + return code; + + link.Read<uint32>(&config.options); + link.Read<BPoint>(&config.offset); + link.Read<int32>(&config.bitmap_id); + return link.ReadString(config.path); +} + + BPrivateScreen::BPrivateScreen(int32 id) : fID(id), @@ -774,3 +877,6 @@ BPrivateScreen::~BPrivateScreen() if (fOwnsColorMap) free(fColorMap); } + + +} // namespace BPrivate diff --git a/src/kits/interface/Screen.cpp b/src/kits/interface/Screen.cpp index 0bb4fef..43686b1 100644 --- a/src/kits/interface/Screen.cpp +++ b/src/kits/interface/Screen.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009, Haiku Inc. + * Copyright 2003-2013, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -186,19 +186,131 @@ BScreen::DesktopColor(uint32 workspace) } -void -BScreen::SetDesktopColor(rgb_color color, bool stick) +status_t +BScreen::SetDesktopColor(rgb_color color, bool makeDefault) +{ + return SetDesktopColor(color, B_CURRENT_WORKSPACE_INDEX, makeDefault); +} + + +status_t +BScreen::SetDesktopColor(rgb_color color, uint32 workspace, bool makeDefault) +{ + if (fScreen == NULL) + return B_ERROR; + + return fScreen->SetDesktopColor(color, workspace, makeDefault); +} + + +// TODO: these would need a bit more work to clone bitmaps locally +#if 0 +BBitmap* +BScreen::DesktopBitmap() const +{ + return DesktopBitmap(B_CURRENT_WORKSPACE_INDEX); +} + + +BBitmap* +BScreen::DesktopBitmap(uint32 workspace) const +{ + if (fScreen != NULL) + return fScreen->DesktopBitmap(workspace); + + return NULL; +} +#endif + + +const char* +BScreen::DesktopImage() const +{ + return DesktopImage(B_CURRENT_WORKSPACE_INDEX); +} + + +const char* +BScreen::DesktopImage(uint32 workspace) const +{ + if (fScreen != NULL) + return fScreen->DesktopImage(workspace); + + return NULL; +} + + +BPoint +BScreen::DesktopImageOffset() const +{ + return DesktopImageOffset(B_CURRENT_WORKSPACE_INDEX); +} + + +BPoint +BScreen::DesktopImageOffset(uint32 workspace) const { if (fScreen != NULL) - fScreen->SetDesktopColor(color, B_CURRENT_WORKSPACE_INDEX, stick); + return fScreen->DesktopImageOffset(workspace); + + return BPoint(); } -void -BScreen::SetDesktopColor(rgb_color color, uint32 workspace, bool stick) +uint32 +BScreen::DesktopImageOptions() const +{ + return DesktopImageOptions(B_CURRENT_WORKSPACE_INDEX); +} + + +uint32 +BScreen::DesktopImageOptions(uint32 workspace) const { if (fScreen != NULL) - fScreen->SetDesktopColor(color, workspace, stick); + return fScreen->DesktopImageOptions(workspace); + + return 0; +} + + +status_t +BScreen::SetDesktopBitmap(BBitmap* bitmap, uint32 options, BPoint offset) +{ + return SetDesktopBitmap(B_CURRENT_WORKSPACE_INDEX, bitmap, options, offset); +} + + +status_t +BScreen::SetDesktopBitmap(uint32 workspace, BBitmap* bitmap, uint32 options, + BPoint offset) +{ + if (fScreen == NULL) + return B_ERROR; + + return fScreen->SetDesktopImage(workspace, NULL, bitmap, options, offset, + false); +} + + +status_t +BScreen::SetDesktopImage(const char* path, BBitmap* bitmap, uint32 options, + BPoint offset, bool makeDefault) +{ + return SetDesktopImage(B_CURRENT_WORKSPACE_INDEX, path, bitmap, options, + offset, makeDefault); +} + + +status_t +BScreen::SetDesktopImage(uint32 workspace, const char* path, BBitmap* bitmap, + uint32 options, BPoint offset, bool makeDefault) +{ + if (fScreen != NULL) { + return fScreen->SetDesktopImage(workspace, path, bitmap, options, + offset, makeDefault); + } + return B_ERROR; } ############################################################################ Commit: 92462fb30ff63f6e5396ed9a625aa059dabb12c7 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Mon Mar 4 22:35:54 2013 UTC app_server: implemented server side AS_{GET|SET}_DESKTOP_IMAGE. * The image isn't yet drawn, though. ---------------------------------------------------------------------------- diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 90651ea..c8ce97a 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -2813,6 +2813,76 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) break; } + case AS_GET_DESKTOP_IMAGE: + { + STRACE(("ServerApp %s: get desktop image\n", Signature())); + + uint32 index; + link.Read<uint32>(&index); + + fDesktop->LockSingleWindow(); + + // we're nice to our children (and also take the default case + // into account which asks for the current workspace) + if (index >= (uint32)kMaxWorkspaces) + index = fDesktop->CurrentWorkspace(); + + Workspace workspace(*fDesktop, index, true); + + fLink.StartMessage(B_OK); + fLink.Attach<uint32>(workspace.BitmapOptions()); + fLink.Attach<BPoint>(workspace.BitmapOffset()); + fLink.Attach<int32>(workspace.Bitmap() != NULL + ? workspace.Bitmap()->Token() : -1); + fLink.AttachString(workspace.ImagePath()); + + fDesktop->UnlockSingleWindow(); + fLink.Flush(); + break; + } + + case AS_SET_DESKTOP_IMAGE: + { + STRACE(("ServerApp %s: set desktop image\n", Signature())); + + uint32 bitmapOptions; + BPoint bitmapOffset; + int32 bitmapToken; + BString imagePath; + uint32 index; + bool makeDefault; + + link.Read<uint32>(&index); + link.Read<uint32>(&bitmapOptions); + link.Read<BPoint>(&bitmapOffset); + link.Read<int32>(&bitmapToken); + link.Read<bool>(&makeDefault); + if (link.ReadString(imagePath) != B_OK) + break; + + fDesktop->LockAllWindows(); + + // we're nice to our children (and also take the default case + // into account which asks for the current workspace) + if (index >= (uint32)kMaxWorkspaces) + index = fDesktop->CurrentWorkspace(); + + ServerBitmap* bitmap = GetBitmap(bitmapToken); + + Workspace workspace(*fDesktop, index); + workspace.SetImage(imagePath.String(), bitmap, bitmapOptions, + bitmapOffset, makeDefault); + + if (bitmap != NULL) + bitmap->ReleaseReference(); + + fDesktop->UnlockAllWindows(); + + fLink.StartMessage(B_OK); + fLink.Flush(); + break; + } + case AS_SET_UI_COLOR: { STRACE(("ServerApp %s: Set UI Color\n", Signature())); ############################################################################ Commit: af954b5cb2f3e9585dc4f2227f2612aaa66cf542 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Tue Mar 5 00:16:19 2013 UTC app_server: actually draw the desktop bitmap. * The drawing is currently very limited, and will just draw the bitmap to fill the screen completely. * Added short test tool to set a background directly in the app_server. * Furthermore, acquiring a bitmap is obviously no guarantee that its buffer will stay in memory; the client memory allocator must not be destroyed as long as its memory is in use. ---------------------------------------------------------------------------- diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index fade9a3..f2e4f8e 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -31,9 +31,9 @@ SYSTEM_BIN = [ FFilterByBuildFeatures query quit rc readlink reindex release renice rlog rm rmattr rmindex rmdir roster route - safemode screen_blanker screenmode screenshot sdiff setdecor setmime settype - setversion setvolume seq sha1sum shar shred shuf shutdown sleep sort - spamdbm split stat strace stty su sum sync sysinfo + safemode screen_blanker screenmode screenshot sdiff setbackground setdecor + setmime settype setversion setvolume seq sha1sum shar shred shuf shutdown + sleep sort spamdbm split stat strace stty su sum sync sysinfo tac tail tcpdump tcptester tee telnet telnetd test timeout top touch tput tr traceroute translate trash true truncate tsort tty uname unchop unexpand unmount uniq unlink unshar unzip unzipsfx diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 4d1f653..a646369 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -166,6 +166,7 @@ StdBinCommands # standard commands that need libbe.so, libtranslation.so, libsupc++.so StdBinCommands + setbackground.cpp translate.cpp : be translation $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; diff --git a/src/bin/setbackground.cpp b/src/bin/setbackground.cpp new file mode 100644 index 0000000..408198d --- /dev/null +++ b/src/bin/setbackground.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 2013, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. + * This file may be used under the terms of the MIT License. + */ + + +#include <stdio.h> +#include <string.h> + +#include <Application.h> +#include <Bitmap.h> +#include <Screen.h> +#include <TranslationUtils.h> + + +int +main(int argc, char** argv) +{ + if (argc < 2) + return 1; + + BApplication app("application/x-vnd.Haiku-setbackground"); + BScreen screen; + + BBitmap* bitmap = BTranslationUtils::GetBitmap(argv[1]); + if (bitmap != NULL) { + status_t status = screen.SetDesktopBitmap(bitmap, 0); + printf("Setting bitmap %g:%g: %s", bitmap->Bounds().Width(), + bitmap->Bounds().Height(), strerror(status)); + } + + return 0; +} diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 4663c0b..3115910 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -401,6 +401,27 @@ workspace_in_workspaces(int32 index, uint32 workspaces) } +/*! Draws a bitmap using the view bitmap options into the specified target + frame. This will only update the region that is covered by \a redrawRegion. +*/ +void +drawViewBitmap(DrawingEngine& drawingEngine, ServerBitmap* bitmap, + uint32 options, const BPoint& offset, const BRect& bitmapRect, + const BRect& viewRect, BRegion& redrawRegion) +{ + drawingEngine.ConstrainClippingRegion(&redrawRegion); + + // TODO: actually implement all options + // TODO: move this into a shared utility source file + // TODO: use from within View::Draw() as well + drawing_mode oldMode; + drawingEngine.SetDrawingMode(B_OP_COPY, oldMode); + drawingEngine.DrawBitmap(bitmap, bitmapRect, viewRect, options); + + drawingEngine.SetDrawingMode(oldMode); +} + + // #pragma mark - @@ -3223,8 +3244,16 @@ Desktop::_SetBackground(BRegion& background) fBackgroundRegion = background; if (dirtyBackground.Frame().IsValid()) { if (GetDrawingEngine()->LockParallelAccess()) { - GetDrawingEngine()->FillRegion(dirtyBackground, - fWorkspaces[fCurrentWorkspace].Color()); + const Workspace::Private& workspace = fWorkspaces[fCurrentWorkspace]; + if (workspace.Bitmap() != NULL) { + drawViewBitmap(*GetDrawingEngine(), workspace.Bitmap(), + workspace.BitmapOptions(), workspace.BitmapOffset(), + workspace.Bitmap()->Bounds(), fVirtualScreen.Frame(), + dirtyBackground); + } else { + GetDrawingEngine()->FillRegion(dirtyBackground, + workspace.Color()); + } GetDrawingEngine()->UnlockParallelAccess(); } diff --git a/src/servers/app/Workspace.cpp b/src/servers/app/Workspace.cpp index 8f9a2d9..1d31cd5 100644 --- a/src/servers/app/Workspace.cpp +++ b/src/servers/app/Workspace.cpp @@ -31,6 +31,8 @@ Workspace::Private::Private() Workspace::Private::~Private() { + if (fBitmap != NULL) + fBitmap->ReleaseReference(); } @@ -51,10 +53,16 @@ void Workspace::Private::SetImage(const char* path, ServerBitmap* bitmap, uint32 options, const BPoint& offset) { + if (fBitmap != NULL) + fBitmap->ReleaseReference(); + fImagePath = path; fBitmap = bitmap; fBitmapOptions = options; fBitmapOffset = offset; + + if (fBitmap != NULL) + fBitmap->AcquireReference(); } @@ -103,6 +111,7 @@ void Workspace::Private::_SetDefaults() { fColor = kDefaultColor; + fBitmap = NULL; }