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
This commit is contained in:
Axel Dörfler
2005-06-15 05:15:26 +00:00
parent 507ff76a65
commit e8fbd2527f
2 changed files with 115 additions and 66 deletions
+62 -29
View File
@@ -18,7 +18,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
Prefs::Prefs() { Prefs::Prefs()
{
BPath path; BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path); find_directory(B_USER_SETTINGS_DIRECTORY, &path);
path.Append("Pulse_settings"); path.Append("Pulse_settings");
@@ -100,21 +101,30 @@ Prefs::Prefs() {
// Use the default size unless it would prevent having at least // Use the default size unless it would prevent having at least
// a one pixel wide display per CPU... this will only happen with > quad // a one pixel wide display per CPU... this will only happen with > quad
i = DEFAULT_DESKBAR_ICON_WIDTH; i = DEFAULT_DESKBAR_ICON_WIDTH;
if (i < GetMinimumViewWidth()) i = GetMinimumViewWidth(); if (i < GetMinimumViewWidth())
i = GetMinimumViewWidth();
if (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) { if (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) {
fatalerror = true; fatalerror = true;
return; return;
} }
} }
BRect Prefs::GetNormalWindowRect() {
Prefs::~Prefs()
{
delete file;
}
BRect
Prefs::GetNormalWindowRect()
{
system_info sys_info; system_info sys_info;
get_system_info(&sys_info); get_system_info(&sys_info);
float height = PROGRESS_MTOP + PROGRESS_MBOTTOM + sys_info.cpu_count * ITEM_OFFSET; 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; height = PULSEVIEW_MIN_HEIGHT;
}
// Dock the window in the lower right hand corner just like the original // Dock the window in the lower right hand corner just like the original
BRect r(0, 0, PULSEVIEW_WIDTH, height); BRect r(0, 0, PULSEVIEW_WIDTH, height);
@@ -123,7 +133,10 @@ BRect Prefs::GetNormalWindowRect() {
return r; return r;
} }
BRect Prefs::GetMiniWindowRect() {
BRect
Prefs::GetMiniWindowRect()
{
// Lower right hand corner by default // Lower right hand corner by default
BRect screen_rect = BScreen(B_MAIN_SCREEN_ID).Frame(); BRect screen_rect = BScreen(B_MAIN_SCREEN_ID).Frame();
screen_rect.left = screen_rect.right - 30; screen_rect.left = screen_rect.right - 30;
@@ -132,7 +145,10 @@ BRect Prefs::GetMiniWindowRect() {
return screen_rect; 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); status_t err = file->ReadAttr(name, B_INT32_TYPE, 0, value, 4);
if (err == B_ENTRY_NOT_FOUND) { if (err == B_ENTRY_NOT_FOUND) {
*value = *defaultvalue; *value = *defaultvalue;
@@ -149,7 +165,10 @@ bool Prefs::GetInt(char *name, int *value, int *defaultvalue) {
return true; 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); status_t err = file->ReadAttr(name, B_BOOL_TYPE, 0, value, 1);
if (err == B_ENTRY_NOT_FOUND) { if (err == B_ENTRY_NOT_FOUND) {
*value = *defaultvalue; *value = *defaultvalue;
@@ -166,7 +185,10 @@ bool Prefs::GetBool(char *name, bool *value, bool *defaultvalue) {
return true; 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)); status_t err = file->ReadAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
if (err == B_ENTRY_NOT_FOUND) { if (err == B_ENTRY_NOT_FOUND) {
*value = *defaultvalue; *value = *defaultvalue;
@@ -183,7 +205,10 @@ bool Prefs::GetRect(char *name, BRect *value, BRect *defaultvalue) {
return true; 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); status_t err = file->WriteAttr(name, B_INT32_TYPE, 0, value, 4);
if (err < 0) { if (err < 0) {
printf("Unknown error writing %s:\n%s\n", name, strerror(err)); printf("Unknown error writing %s:\n%s\n", name, strerror(err));
@@ -193,7 +218,10 @@ bool Prefs::PutInt(char *name, int *value){
return true; 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); status_t err = file->WriteAttr(name, B_BOOL_TYPE, 0, value, 1);
if (err < 0) { if (err < 0) {
printf("Unknown error writing %s:\n%s\n", name, strerror(err)); printf("Unknown error writing %s:\n%s\n", name, strerror(err));
@@ -203,7 +231,10 @@ bool Prefs::PutBool(char *name, bool *value) {
return true; 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)); status_t err = file->WriteAttr(name, B_RECT_TYPE, 0, value, sizeof(BRect));
if (err < 0) { if (err < 0) {
printf("Unknown error writing %s:\n%s\n", name, strerror(err)); printf("Unknown error writing %s:\n%s\n", name, strerror(err));
@@ -213,23 +244,25 @@ bool Prefs::PutRect(char *name, BRect *value) {
return true; return true;
} }
bool Prefs::Save() {
if (!PutInt("window_mode", &window_mode)) return false; bool
if (!PutRect("normal_window_rect", &normal_window_rect)) return false; Prefs::Save()
if (!PutRect("mini_window_rect", &mini_window_rect)) return false; {
if (!PutRect("prefs_window_rect", &prefs_window_rect)) return false; if (!PutInt("window_mode", &window_mode)
if (!PutInt("normal_bar_color", &normal_bar_color)) return false; || !PutRect("normal_window_rect", &normal_window_rect)
if (!PutInt("mini_active_color", &mini_active_color)) return false; || !PutRect("mini_window_rect", &mini_window_rect)
if (!PutInt("mini_idle_color", &mini_idle_color)) return false; || !PutRect("prefs_window_rect", &prefs_window_rect)
if (!PutInt("mini_frame_color", &mini_frame_color)) return false; || !PutInt("normal_bar_color", &normal_bar_color)
if (!PutInt("deskbar_active_color", &deskbar_active_color)) return false; || !PutInt("mini_active_color", &mini_active_color)
if (!PutInt("deskbar_idle_color", &deskbar_idle_color)) return false; || !PutInt("mini_idle_color", &mini_idle_color)
if (!PutInt("deskbar_frame_color", &deskbar_frame_color)) return false; || !PutInt("mini_frame_color", &mini_frame_color)
if (!PutBool("normal_fade_colors", &normal_fade_colors)) return false; || !PutInt("deskbar_active_color", &deskbar_active_color)
if (!PutInt("deskbar_icon_width", &deskbar_icon_width)) return false; || !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; return true;
} }
Prefs::~Prefs() {
delete file;
}
+38 -22
View File
@@ -16,9 +16,10 @@
#include "PulseWindow.h" #include "PulseWindow.h"
#include "DeskbarPulseView.h" #include "DeskbarPulseView.h"
#include <interface/Alert.h> #include <Alert.h>
#include <interface/Rect.h> #include <Rect.h>
#include <interface/Deskbar.h> #include <Screen.h>
#include <Deskbar.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@@ -118,25 +119,38 @@ PulseApp::PulseApp(int argc, char **argv)
void void
PulseApp::BuildPulse() 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 // 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; return true;
for (int x = 0; x < sys_info.cpu_count; x++) { for (int x = 0; x < sys_info.cpu_count; x++) {
if (x == my_cpu) continue; if (x == my_cpu)
if (_kget_cpu_state_(x) == 1) return false; continue;
if (_kget_cpu_state_(x) == 1)
return false;
} }
return true; return true;
} }