From ae0606be749b5b16f3ec706c24bcb488d7f5ac96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 12 Aug 2008 17:39:42 +0000 Subject: [PATCH] * Added two more private InterfaceDefs functions: get_application_order(), and get_window_order() will retrieve the application respectively window order on the selected workspace. * Moved private BeOS compatible functions (as used by the Deskbar) into the private WindowInfo.h header. * Whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26951 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/ServerProtocol.h | 6 +- headers/private/interface/WindowInfo.h | 19 +++ src/kits/interface/InterfaceDefs.cpp | 207 +++++++++++++++---------- src/servers/app/Desktop.cpp | 107 +++++++++++++ src/servers/app/Desktop.h | 4 + src/servers/app/ServerApp.cpp | 20 ++- 6 files changed, 277 insertions(+), 86 deletions(-) diff --git a/headers/private/app/ServerProtocol.h b/headers/private/app/ServerProtocol.h index 73067f465a..860d8ba5a3 100644 --- a/headers/private/app/ServerProtocol.h +++ b/headers/private/app/ServerProtocol.h @@ -41,6 +41,8 @@ enum { AS_MINIMIZE_TEAM, AS_BRING_TEAM_TO_FRONT, AS_WINDOW_ACTION, + AS_GET_APPLICATION_ORDER, + AS_GET_WINDOW_ORDER, // Application definitions AS_CREATE_APP, @@ -78,7 +80,7 @@ enum { AS_QUIT_WINDOW, AS_SEND_BEHIND, AS_SET_LOOK, - AS_SET_FEEL, + AS_SET_FEEL, AS_SET_FLAGS, AS_DISABLE_UPDATES, AS_ENABLE_UPDATES, @@ -154,7 +156,7 @@ enum { AS_GET_ACCELERANT_INFO, AS_GET_MONITOR_INFO, AS_GET_FRAME_BUFFER_CONFIG, - + AS_SET_DPMS, AS_GET_DPMS_STATE, AS_GET_DPMS_CAPABILITIES, diff --git a/headers/private/interface/WindowInfo.h b/headers/private/interface/WindowInfo.h index 726c183c14..8e52d81eb2 100644 --- a/headers/private/interface/WindowInfo.h +++ b/headers/private/interface/WindowInfo.h @@ -42,4 +42,23 @@ enum window_action { B_BRING_TO_FRONT }; + +// Private BeOS compatible window API + +void do_window_action(int32 window_id, int32 action, BRect zoomRect, bool zoom); +client_window_info* get_window_info(int32 token); +int32* get_token_list(team_id app, int32 *count); +void do_bring_to_front_team(BRect zoomRect, team_id app, bool zoom); +void do_minimize_team(BRect zoomRect, team_id app, bool zoom); + +// Haiku additions + +namespace BPrivate { + +status_t get_application_order(int32 workspace, team_id** _apps, int32* _count); +status_t get_window_order(int32 workspace, int32** _tokens, int32* _count); + +} // namespace BPrivate + + #endif // _WINDOW_INFO_H_ diff --git a/src/kits/interface/InterfaceDefs.cpp b/src/kits/interface/InterfaceDefs.cpp index 2a6fd2c6cd..5fb6516536 100644 --- a/src/kits/interface/InterfaceDefs.cpp +++ b/src/kits/interface/InterfaceDefs.cpp @@ -311,21 +311,21 @@ set_screen_space(int32 index, uint32 space, bool stick) uint32 depth; if (!BPrivate::get_mode_parameter(space, width, height, depth)) return B_BAD_VALUE; - + BScreen screen(B_MAIN_SCREEN_ID); display_mode mode; - + // TODO: What about refresh rate ? // currently we get it from the current video mode, but // this might be not so wise. status_t status = screen.GetMode(index, &mode); if (status < B_OK) return status; - + mode.virtual_width = width; mode.virtual_height = height; mode.space = depth; - + return screen.SetMode(index, &mode, stick); } @@ -358,10 +358,10 @@ set_scroll_bar_info(scroll_bar_info *info) BPrivate::AppServerLink link; int32 code; - + link.StartMessage(AS_SET_SCROLLBAR_INFO); link.Attach(*info); - + if (link.FlushWithReply(code) == B_OK && code == B_OK) return B_OK; @@ -375,12 +375,12 @@ get_mouse_type(int32 *type) { BMessage command(IS_GET_MOUSE_TYPE); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("mouse_type", type) != B_OK) return B_ERROR; - + return B_OK; } @@ -403,14 +403,14 @@ get_mouse_map(mouse_map *map) BMessage reply; const void *data = 0; ssize_t count; - + _control_input_server_(&command, &reply); - + if (reply.FindData("mousemap", B_RAW_TYPE, &data, &count) != B_OK) return B_ERROR; - + memcpy(map, data, count); - + return B_OK; } @@ -420,7 +420,7 @@ set_mouse_map(mouse_map *map) { BMessage command(IS_SET_MOUSE_MAP); BMessage reply; - + command.AddData("mousemap", B_RAW_TYPE, map, sizeof(mouse_map)); return _control_input_server_(&command, &reply); } @@ -431,12 +431,12 @@ get_click_speed(bigtime_t *speed) { BMessage command(IS_GET_CLICK_SPEED); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt64("speed", speed) != B_OK) *speed = 500000; - + return B_OK; } @@ -456,12 +456,12 @@ get_mouse_speed(int32 *speed) { BMessage command(IS_GET_MOUSE_SPEED); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("speed", speed) != B_OK) *speed = 65536; - + return B_OK; } @@ -481,12 +481,12 @@ get_mouse_acceleration(int32 *speed) { BMessage command(IS_GET_MOUSE_ACCELERATION); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("speed", speed) != B_OK) *speed = 65536; - + return B_OK; } @@ -506,9 +506,9 @@ get_key_repeat_rate(int32 *rate) { BMessage command(IS_GET_KEY_REPEAT_RATE); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("rate", rate) != B_OK) *rate = 250000; @@ -531,12 +531,12 @@ get_key_repeat_delay(bigtime_t *delay) { BMessage command(IS_GET_KEY_REPEAT_DELAY); BMessage reply; - + _control_input_server_(&command, &reply); - + if (reply.FindInt64("delay", delay) != B_OK) *delay = 200; - + return B_OK; } @@ -557,12 +557,12 @@ modifiers() BMessage command(IS_GET_MODIFIERS); BMessage reply; int32 err, modifier; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("status", &err) != B_OK) return 0; - + if (reply.FindInt32("modifiers", &modifier) != B_OK) return 0; @@ -578,15 +578,15 @@ get_key_info(key_info *info) const void *data = 0; int32 err; ssize_t count; - + _control_input_server_(&command, &reply); - + if (reply.FindInt32("status", &err) != B_OK) return B_ERROR; - + if (reply.FindData("key_info", B_ANY_TYPE, &data, &count) != B_OK) return B_ERROR; - + memcpy(info, data, count); return B_OK; } @@ -608,19 +608,19 @@ _get_key_map(key_map **map, char **key_buffer, ssize_t *key_buffer_size) const void *map_array = 0, *key_array = 0; if (key_buffer_size == NULL) key_buffer_size = &key_count; - + _control_input_server_(&command, &reply); - + if (reply.FindData("keymap", B_ANY_TYPE, &map_array, &map_count) != B_OK) { *map = 0; *key_buffer = 0; return; } - + if (reply.FindData("key_buffer", B_ANY_TYPE, &key_array, key_buffer_size) != B_OK) { *map = 0; *key_buffer = 0; return; } - + *map = (key_map *)malloc(map_count); memcpy(*map, map_array, map_count); *key_buffer = (char *)malloc(*key_buffer_size); @@ -634,12 +634,12 @@ get_keyboard_id(uint16 *id) BMessage command(IS_GET_KEYBOARD_ID); BMessage reply; uint16 kid; - + _control_input_server_(&command, &reply); - + reply.FindInt16("id", (int16 *)&kid); *id = kid; - + return B_OK; } @@ -649,7 +649,7 @@ set_modifier_key(uint32 modifier, uint32 key) { BMessage command(IS_SET_MODIFIER_KEY); BMessage reply; - + command.AddInt32("modifier", modifier); command.AddInt32("key", key); _control_input_server_(&command, &reply); @@ -661,7 +661,7 @@ set_keyboard_locks(uint32 modifiers) { BMessage command(IS_SET_KEYBOARD_LOCKS); BMessage reply; - + command.AddInt32("locks", modifiers); _control_input_server_(&command, &reply); } @@ -673,7 +673,7 @@ _restore_key_map_() BMessage message(IS_RESTORE_KEY_MAP); BMessage reply; - return _control_input_server_(&message, &reply); + return _control_input_server_(&message, &reply); } @@ -717,7 +717,7 @@ current_workspace() int32 index = 0; BPrivate::AppServerLink link; - link.StartMessage(AS_CURRENT_WORKSPACE); + link.StartMessage(AS_CURRENT_WORKSPACE); int32 status; if (link.FlushWithReply(status) == B_OK && status == B_OK) @@ -758,7 +758,7 @@ run_select_printer_panel() { if (be_roster == NULL) return; - + // Launches the Printer prefs app via the Roster be_roster->Launch(PRNT_SIGNATURE_TYPE); } @@ -767,12 +767,12 @@ run_select_printer_panel() void run_add_printer_panel() { - // Launches the Printer prefs app via the Roster and asks it to + // Launches the Printer prefs app via the Roster and asks it to // add a printer run_select_printer_panel(); BMessenger printerPanelMessenger(PRNT_SIGNATURE_TYPE); - printerPanelMessenger.SendMessage(PRINTERS_ADD_PRINTER); + printerPanelMessenger.SendMessage(PRINTERS_ADD_PRINTER); } @@ -814,14 +814,14 @@ mouse_mode() { // Gets the focus-follows-mouse style, such as normal, B_WARP_MOUSE, etc. mode_mouse mode = B_NORMAL_MOUSE; - + BPrivate::AppServerLink link; link.StartMessage(AS_GET_MOUSE_MODE); int32 code; if (link.FlushWithReply(code) == B_OK && code == B_OK) link.Read(&mode); - + return mode; } @@ -914,7 +914,7 @@ _init_interface_kit_() _init_global_fonts_(); _menu_info_ptr_ = &BMenu::sMenuInfo; - + status = get_menu_info(&BMenu::sMenuInfo); general_info.background_color = ui_color(B_PANEL_BACKGROUND_COLOR); @@ -933,7 +933,7 @@ extern "C" status_t _fini_interface_kit_() { //TODO: Implement ? - + return B_OK; } @@ -946,7 +946,7 @@ _fini_interface_kit_() Note, we don't have to be compatible here, and could just change the Deskbar not to use this anymore \param theme The theme to choose - + - \c 0: BeOS - \c 1: AmigaOS - \c 2: Win95 @@ -978,14 +978,14 @@ count_decorators(void) int32 count = -1; if (link.FlushWithReply(code) == B_OK && code == B_OK) link.Read(&count); - + return count; } /*! \brief queries the server for the index of the current decorators \return the current decorator's index - + If for some bizarre reason this function fails, it returns -1 */ int32 @@ -1034,7 +1034,7 @@ get_decorator_name(const int32 &index, BString &name) \param index The index of the decorator to get the name for \param bitmap BBitmap to receive the preview \return B_OK if successful, B_ERROR if not. - + This is currently unimplemented. */ status_t @@ -1048,7 +1048,7 @@ get_decorator_preview(const int32 &index, BBitmap *bitmap) /*! \brief Private function which sets the window decorator for the system. \param index Index of the decorator to set - + If the index is invalid, this function and the server do nothing */ status_t @@ -1067,30 +1067,73 @@ set_decorator(const int32 &index) } +status_t +get_application_order(int32 workspace, team_id** _applications, + int32* _count) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_APPLICATION_ORDER); + link.Attach(workspace); + + int32 code; + status_t status = link.FlushWithReply(code); + if (status != B_OK) + return status; + if (code != B_OK) + return code; + + int32 count; + link.Read(&count); + + *_applications = (team_id*)malloc(count * sizeof(team_id)); + if (*_applications == NULL) + return B_NO_MEMORY; + + link.Read(*_applications, count * sizeof(team_id)); + *_count = count; + return B_OK; +} + + +status_t +get_window_order(int32 workspace, int32** _tokens, int32* _count) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_WINDOW_ORDER); + link.Attach(workspace); + + int32 code; + status_t status = link.FlushWithReply(code); + if (status != B_OK) + return status; + if (code != B_OK) + return code; + + int32 count; + link.Read(&count); + + *_tokens = (int32*)malloc(count * sizeof(int32)); + if (*_tokens == NULL) + return B_NO_MEMORY; + + link.Read(*_tokens, count * sizeof(int32)); + *_count = count; + return B_OK; +} + + } // namespace BPrivate // These methods were marked with "Danger, will Robinson!" in // the OpenTracker source, so we might not want to be compatible // here. -// In any way, we would need to update Deskbar to use our +// In any way, we would need to update Deskbar to use our // replacements, so we could as well just implement them... -// -// They are defined (also the complete window_info structure) in -// src/apps/deskbar/WindowMenuItem.h -struct window_info; - -void do_window_action(int32 window_id, int32 action, - BRect zoomRect, bool zoom); -window_info *get_window_info(int32 a_token); -int32 *get_token_list(team_id app, int32 *count); -void do_bring_to_front_team(BRect zoomRect, team_id app, bool zoom); -void do_minimize_team(BRect zoomRect, team_id team, bool zoom); - - -void -do_window_action(int32 windowToken, int32 action, - BRect zoomRect, bool zoom) +void +do_window_action(int32 windowToken, int32 action, BRect zoomRect, bool zoom) { BPrivate::AppServerLink link; @@ -1103,11 +1146,11 @@ do_window_action(int32 windowToken, int32 action, } -window_info * +client_window_info* get_window_info(int32 serverToken) { BPrivate::AppServerLink link; - + link.StartMessage(AS_GET_WINDOW_INFO); link.Attach(serverToken); @@ -1117,7 +1160,7 @@ get_window_info(int32 serverToken) int32 size; link.Read(&size); - + client_window_info* info = (client_window_info*)malloc(size); if (info == NULL) return NULL; @@ -1127,8 +1170,8 @@ get_window_info(int32 serverToken) } -int32 * -get_token_list(team_id team, int32 *_count) +int32* +get_token_list(team_id team, int32* _count) { BPrivate::AppServerLink link; @@ -1321,7 +1364,7 @@ truncate_middle(const char* source, char* dest, uint32 numChars, strcpy(dest, ""); return true; } - + // see if the gap between left/right is smaller than the ellipsis float totalWidth = rightWidth + leftWidth; @@ -1339,7 +1382,7 @@ truncate_middle(const char* source, char* dest, uint32 numChars, // The ellipsis now definitely fits, but let's // see if we can add another character - + totalWidth = ellipsisWidth + rightWidth + leftWidth; if (left > numChars - right) { diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 8df7da5c02..bdc1dddd2b 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -2491,6 +2491,113 @@ Desktop::WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender) } +void +Desktop::WriteWindowOrder(int32 workspace, BPrivate::LinkSender& sender) +{ + LockSingleWindow(); + + if (workspace < 0) + workspace = fCurrentWorkspace; + else if (workspace >= kMaxWorkspaces) { + sender.StartMessage(B_BAD_VALUE); + sender.Flush(); + UnlockSingleWindow(); + return; + } + + // compute the number of windows + + int32 count = 0; + + for (Window *window = _Windows(workspace).LastWindow(); window != NULL; + window = window->PreviousWindow(workspace)) { + count++; + } + + // write list + + sender.StartMessage(B_OK); + sender.Attach(count); + + for (Window *window = _Windows(workspace).LastWindow(); window != NULL; + window = window->PreviousWindow(workspace)) { + sender.Attach(window->ServerWindow()->ServerToken()); + } + + sender.Flush(); + + UnlockSingleWindow(); +} + + +void +Desktop::WriteApplicationOrder(int32 workspace, BPrivate::LinkSender& sender) +{ + fApplicationsLock.Lock(); + LockSingleWindow(); + + int32 maxCount = fApplications.CountItems(); + + fApplicationsLock.Unlock(); + // as long as we hold the window lock, no new window can appear + + if (workspace < 0) + workspace = fCurrentWorkspace; + else if (workspace >= kMaxWorkspaces) { + sender.StartMessage(B_BAD_VALUE); + sender.Flush(); + UnlockSingleWindow(); + return; + } + + // compute the list of applications on this workspace + + team_id* teams = (team_id*)malloc(maxCount * sizeof(team_id)); + if (teams == NULL) { + sender.StartMessage(B_NO_MEMORY); + sender.Flush(); + UnlockSingleWindow(); + return; + } + + int32 count = 0; + + for (Window *window = _Windows(workspace).LastWindow(); window != NULL; + window = window->PreviousWindow(workspace)) { + team_id team = window->ServerWindow()->ClientTeam(); + if (count > 1) { + // see if we already have this team + bool found = false; + for (int32 i = 0; i < count; i++) { + if (teams[i] == team) { + found = true; + break; + } + } + if (found) + continue; + } + + ASSERT(count < maxCount); + teams[count++] = team; + } + + UnlockSingleWindow(); + + // write list + + sender.StartMessage(B_OK); + sender.Attach(count); + + for (int32 i = 0; i < count; i++) { + sender.Attach(teams[i]); + } + + sender.Flush(); + free(teams); +} + + void Desktop::MarkDirty(BRegion& region) { diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index 5c7d55ec15..0f7660975e 100644 --- a/src/servers/app/Desktop.h +++ b/src/servers/app/Desktop.h @@ -210,6 +210,10 @@ class Desktop : public MessageLooper, public ScreenOwner { BPrivate::LinkSender& sender); void WriteWindowInfo(int32 serverToken, BPrivate::LinkSender& sender); + void WriteApplicationOrder(int32 workspace, + BPrivate::LinkSender& sender); + void WriteWindowOrder(int32 workspace, + BPrivate::LinkSender& sender); private: void _LaunchInputServer(); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index bc26eb00a2..bb4cde1ddf 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -470,6 +470,22 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) break; } + case AS_GET_WINDOW_ORDER: + { + int32 workspace; + if (link.Read(&workspace) == B_OK) + fDesktop->WriteWindowOrder(workspace, fLink.Sender()); + break; + } + + case AS_GET_APPLICATION_ORDER: + { + int32 workspace; + if (link.Read(&workspace) == B_OK) + fDesktop->WriteApplicationOrder(workspace, fLink.Sender()); + break; + } + case AS_MINIMIZE_TEAM: { team_id team; @@ -2576,7 +2592,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) fLink.Flush(); break; } - + case AS_SET_SUBPIXEL_AVERAGE_WEIGHT: { uint8 averageWeight; @@ -2596,7 +2612,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) fLink.Flush(); break; } - + case AS_SET_SUBPIXEL_ORDERING: { bool subpixelOrdering;