From e8fbd2527f74124c33be0309aea035b43e4d6dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 15 Jun 2005 05:15:26 +0000 Subject: [PATCH] Now checks if the window is out of the screen frame and move the window back into it, if necessary. Some more cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13142 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/pulse/Prefs.cpp | 121 +++++++++++++++++++++++------------- src/apps/pulse/PulseApp.cpp | 60 +++++++++++------- 2 files changed, 115 insertions(+), 66 deletions(-) diff --git a/src/apps/pulse/Prefs.cpp b/src/apps/pulse/Prefs.cpp index 29d0d0bf24..f6fea06e08 100644 --- a/src/apps/pulse/Prefs.cpp +++ b/src/apps/pulse/Prefs.cpp @@ -18,104 +18,114 @@ #include #include -Prefs::Prefs() { +Prefs::Prefs() +{ BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Pulse_settings"); file = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE); - + int i = NORMAL_WINDOW_MODE; if (!GetInt("window_mode", &window_mode, &i)) { fatalerror = true; return; } - + // These three prefs require a connection to the app_server BRect r = GetNormalWindowRect(); if (!GetRect("normal_window_rect", &normal_window_rect, &r)) { fatalerror = true; return; } - + r = GetMiniWindowRect(); if (!GetRect("mini_window_rect", &mini_window_rect, &r)) { fatalerror = true; return; } - + r.Set(100, 100, 415, 329); if (!GetRect("prefs_window_rect", &prefs_window_rect, &r)) { fatalerror = true; return; } - + i = DEFAULT_NORMAL_BAR_COLOR; if (!GetInt("normal_bar_color", &normal_bar_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_MINI_ACTIVE_COLOR; if (!GetInt("mini_active_color", &mini_active_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_MINI_IDLE_COLOR; if (!GetInt("mini_idle_color", &mini_idle_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_MINI_FRAME_COLOR; if (!GetInt("mini_frame_color", &mini_frame_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_DESKBAR_ACTIVE_COLOR; if (!GetInt("deskbar_active_color", &deskbar_active_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_DESKBAR_IDLE_COLOR; if (!GetInt("deskbar_idle_color", &deskbar_idle_color, &i)) { fatalerror = true; return; } - + i = DEFAULT_DESKBAR_FRAME_COLOR; if (!GetInt("deskbar_frame_color", &deskbar_frame_color, &i)) { fatalerror = true; return; } - + bool b = DEFAULT_NORMAL_FADE_COLORS; if (!GetBool("normal_fade_colors", &normal_fade_colors, &b)) { fatalerror = true; return; } - + // Use the default size unless it would prevent having at least // a one pixel wide display per CPU... this will only happen with > quad i = DEFAULT_DESKBAR_ICON_WIDTH; - if (i < GetMinimumViewWidth()) i = GetMinimumViewWidth(); + if (i < GetMinimumViewWidth()) + i = GetMinimumViewWidth(); if (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) { fatalerror = true; return; } } -BRect Prefs::GetNormalWindowRect() { + +Prefs::~Prefs() +{ + delete file; +} + + +BRect +Prefs::GetNormalWindowRect() +{ system_info sys_info; get_system_info(&sys_info); - + float height = PROGRESS_MTOP + PROGRESS_MBOTTOM + sys_info.cpu_count * ITEM_OFFSET; - if (PULSEVIEW_MIN_HEIGHT > height) { + if (PULSEVIEW_MIN_HEIGHT > height) height = PULSEVIEW_MIN_HEIGHT; - } - + // Dock the window in the lower right hand corner just like the original BRect r(0, 0, PULSEVIEW_WIDTH, height); BRect screen_rect = BScreen(B_MAIN_SCREEN_ID).Frame(); @@ -123,7 +133,10 @@ BRect Prefs::GetNormalWindowRect() { return r; } -BRect Prefs::GetMiniWindowRect() { + +BRect +Prefs::GetMiniWindowRect() +{ // Lower right hand corner by default BRect screen_rect = BScreen(B_MAIN_SCREEN_ID).Frame(); screen_rect.left = screen_rect.right - 30; @@ -132,7 +145,10 @@ BRect Prefs::GetMiniWindowRect() { return screen_rect; } -bool Prefs::GetInt(char *name, int *value, int *defaultvalue) { + +bool +Prefs::GetInt(char *name, int *value, int *defaultvalue) +{ status_t err = file->ReadAttr(name, B_INT32_TYPE, 0, value, 4); if (err == B_ENTRY_NOT_FOUND) { *value = *defaultvalue; @@ -149,7 +165,10 @@ bool Prefs::GetInt(char *name, int *value, int *defaultvalue) { return true; } -bool Prefs::GetBool(char *name, bool *value, bool *defaultvalue) { + +bool +Prefs::GetBool(char *name, bool *value, bool *defaultvalue) +{ status_t err = file->ReadAttr(name, B_BOOL_TYPE, 0, value, 1); if (err == B_ENTRY_NOT_FOUND) { *value = *defaultvalue; @@ -166,7 +185,10 @@ bool Prefs::GetBool(char *name, bool *value, bool *defaultvalue) { return true; } -bool Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue) { + +bool +Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue) +{ status_t err = file->ReadAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect)); if (err == B_ENTRY_NOT_FOUND) { *value = *defaultvalue; @@ -183,7 +205,10 @@ bool Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue) { return true; } -bool Prefs::PutInt(char *name, int *value){ + +bool +Prefs::PutInt(char *name, int *value) +{ status_t err = file->WriteAttr(name, B_INT32_TYPE, 0, value, 4); if (err < 0) { printf("Unknown error writing %s:\n%s\n", name, strerror(err)); @@ -193,7 +218,10 @@ bool Prefs::PutInt(char *name, int *value){ return true; } -bool Prefs::PutBool(char *name, bool *value) { + +bool +Prefs::PutBool(char *name, bool *value) +{ status_t err = file->WriteAttr(name, B_BOOL_TYPE, 0, value, 1); if (err < 0) { printf("Unknown error writing %s:\n%s\n", name, strerror(err)); @@ -203,7 +231,10 @@ bool Prefs::PutBool(char *name, bool *value) { return true; } -bool Prefs::PutRect(char *name, BRect *value) { + +bool +Prefs::PutRect(char *name, BRect *value) +{ status_t err = file->WriteAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect)); if (err < 0) { printf("Unknown error writing %s:\n%s\n", name, strerror(err)); @@ -213,23 +244,25 @@ bool Prefs::PutRect(char *name, BRect *value) { return true; } -bool Prefs::Save() { - if (!PutInt("window_mode", &window_mode)) return false; - if (!PutRect("normal_window_rect", &normal_window_rect)) return false; - if (!PutRect("mini_window_rect", &mini_window_rect)) return false; - if (!PutRect("prefs_window_rect", &prefs_window_rect)) return false; - if (!PutInt("normal_bar_color", &normal_bar_color)) return false; - if (!PutInt("mini_active_color", &mini_active_color)) return false; - if (!PutInt("mini_idle_color", &mini_idle_color)) return false; - if (!PutInt("mini_frame_color", &mini_frame_color)) return false; - if (!PutInt("deskbar_active_color", &deskbar_active_color)) return false; - if (!PutInt("deskbar_idle_color", &deskbar_idle_color)) return false; - if (!PutInt("deskbar_frame_color", &deskbar_frame_color)) return false; - if (!PutBool("normal_fade_colors", &normal_fade_colors)) return false; - if (!PutInt("deskbar_icon_width", &deskbar_icon_width)) return false; + +bool +Prefs::Save() +{ + if (!PutInt("window_mode", &window_mode) + || !PutRect("normal_window_rect", &normal_window_rect) + || !PutRect("mini_window_rect", &mini_window_rect) + || !PutRect("prefs_window_rect", &prefs_window_rect) + || !PutInt("normal_bar_color", &normal_bar_color) + || !PutInt("mini_active_color", &mini_active_color) + || !PutInt("mini_idle_color", &mini_idle_color) + || !PutInt("mini_frame_color", &mini_frame_color) + || !PutInt("deskbar_active_color", &deskbar_active_color) + || !PutInt("deskbar_idle_color", &deskbar_idle_color) + || !PutInt("deskbar_frame_color", &deskbar_frame_color) + || !PutBool("normal_fade_colors", &normal_fade_colors) + || !PutInt("deskbar_icon_width", &deskbar_icon_width)) + return false; + return true; } -Prefs::~Prefs() { - delete file; -} diff --git a/src/apps/pulse/PulseApp.cpp b/src/apps/pulse/PulseApp.cpp index 67e305bde9..4feba5d491 100644 --- a/src/apps/pulse/PulseApp.cpp +++ b/src/apps/pulse/PulseApp.cpp @@ -16,9 +16,10 @@ #include "PulseWindow.h" #include "DeskbarPulseView.h" -#include -#include -#include +#include +#include +#include +#include #include #include @@ -118,25 +119,38 @@ PulseApp::PulseApp(int argc, char **argv) void PulseApp::BuildPulse() { - PulseWindow *pulsewindow = NULL; - if (prefs->window_mode == NORMAL_WINDOW_MODE) { - pulsewindow = new PulseWindow(prefs->normal_window_rect); - } else if (prefs->window_mode == MINI_WINDOW_MODE) { - pulsewindow = new PulseWindow(prefs->mini_window_rect); // Remove this case for Deskbar add on API - } else if (prefs->window_mode == DESKBAR_MODE) { - if (LoadInDeskbar()) { - PostMessage(new BMessage(B_QUIT_REQUESTED)); - return; - } else { - // If loading the replicant fails, launch the app instead - // This allows having the replicant and the app open simultaneously - prefs->window_mode = NORMAL_WINDOW_MODE; - pulsewindow = new PulseWindow(prefs->normal_window_rect); - } - } - pulsewindow->Show(); + // If loading the replicant fails, launch the app instead + // This allows having the replicant and the app open simultaneously + if (prefs->window_mode == DESKBAR_MODE && LoadInDeskbar()) { + PostMessage(new BMessage(B_QUIT_REQUESTED)); + return; + } else + prefs->window_mode = NORMAL_WINDOW_MODE; + + PulseWindow *pulseWindow = NULL; + + if (prefs->window_mode == MINI_WINDOW_MODE) + pulseWindow = new PulseWindow(prefs->mini_window_rect); + else + pulseWindow = new PulseWindow(prefs->normal_window_rect); + + // check if the window is on screen, and move it if not + BRect frame = pulseWindow->Frame(); + BRect screenFrame = BScreen().Frame(); + + if (frame.left > screenFrame.right) + pulseWindow->MoveBy(screenFrame.right - frame.right - 10, 0); + else if (frame.right < 0) + pulseWindow->MoveTo(10, frame.top); + + if (frame.top > screenFrame.bottom) + pulseWindow->MoveBy(0, screenFrame.bottom - frame.bottom - 10); + else if (frame.bottom < 0) + pulseWindow->MoveTo(frame.left, 10); + + pulseWindow->Show(); } @@ -169,8 +183,10 @@ LastEnabledCPU(int my_cpu) return true; for (int x = 0; x < sys_info.cpu_count; x++) { - if (x == my_cpu) continue; - if (_kget_cpu_state_(x) == 1) return false; + if (x == my_cpu) + continue; + if (_kget_cpu_state_(x) == 1) + return false; } return true; }