void ConfigView::UpdateDeskbarIconWidth() { // Make sure the width shows at least one pixel per CPU and // that it will fit in the tray in any Deskbar orientation int width = atoi(fIconWidthControl->Text()); int min_width = GetMinimumViewWidth(); if (width < min_width || width > 50) { char temp[10]; if (width < min_width) { sprintf(temp, "%d", min_width); width = min_width; } else { strcpy(temp, "50"); width = 50; } fIconWidthControl->SetText(temp); } fPrefs->deskbar_icon_width = width; BMessage message(PRV_DESKBAR_ICON_WIDTH); message.AddInt32("width", width); fTarget.SendMessage(&message); }
bool LoadInDeskbar() { PulseApp *pulseapp = (PulseApp *)be_app; BDeskbar *deskbar = new BDeskbar(); // Don't allow two copies in the Deskbar at once if (deskbar->HasItem("DeskbarPulseView")) { delete deskbar; return false; } // Must be 16 pixels high, the width is retrieved from the Prefs class int width = pulseapp->prefs->deskbar_icon_width; int min_width = GetMinimumViewWidth(); if (width < min_width) { pulseapp->prefs->deskbar_icon_width = min_width; width = min_width; } BRect rect(0, 0, width - 1, 15); DeskbarPulseView *replicant = new DeskbarPulseView(rect); status_t err = deskbar->AddItem(replicant); delete replicant; delete deskbar; if (err != B_OK) { BAlert *alert = new BAlert(NULL, strerror(err), "OK"); alert->Go(NULL); return false; } return true; }
PulseWindow::PulseWindow(BRect rect) : BWindow(rect, B_TRANSLATE_SYSTEM_NAME("Pulse"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) { SetPulseRate(200000); PulseApp *pulseapp = (PulseApp *)be_app; BRect bounds = Bounds(); fNormalPulseView = new NormalPulseView(bounds); AddChild(fNormalPulseView); fMiniPulseView = new MiniPulseView(bounds, "MiniPulseView", pulseapp->prefs); AddChild(fMiniPulseView); fMode = pulseapp->prefs->window_mode; if (fMode == MINI_WINDOW_MODE) { SetLook(B_MODAL_WINDOW_LOOK); SetFeel(B_NORMAL_WINDOW_FEEL); SetFlags(B_NOT_ZOOMABLE); fNormalPulseView->Hide(); SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); ResizeTo(rect.Width(), rect.Height()); } else fMiniPulseView->Hide(); fPrefsWindow = NULL; }
void PulseWindow::SetMode(int newmode) { PulseApp *pulseapp = (PulseApp *)be_app; switch (newmode) { case PV_NORMAL_MODE: if (fMode == MINI_WINDOW_MODE) { pulseapp->prefs->mini_window_rect = Frame(); pulseapp->prefs->window_mode = NORMAL_WINDOW_MODE; pulseapp->prefs->Save(); } fMiniPulseView->Hide(); fNormalPulseView->Show(); fMode = NORMAL_WINDOW_MODE; SetType(B_TITLED_WINDOW); SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE); ResizeTo(pulseapp->prefs->normal_window_rect.IntegerWidth(), pulseapp->prefs->normal_window_rect.IntegerHeight()); MoveTo(pulseapp->prefs->normal_window_rect.left, pulseapp->prefs->normal_window_rect.top); MoveOnScreen(); break; case PV_MINI_MODE: if (fMode == NORMAL_WINDOW_MODE) { pulseapp->prefs->normal_window_rect = Frame(); pulseapp->prefs->window_mode = MINI_WINDOW_MODE; pulseapp->prefs->Save(); } fNormalPulseView->Hide(); fMiniPulseView->Show(); fMode = MINI_WINDOW_MODE; SetLook(B_MODAL_WINDOW_LOOK); SetFeel(B_NORMAL_WINDOW_FEEL); SetFlags(B_NOT_ZOOMABLE); SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096); ResizeTo(pulseapp->prefs->mini_window_rect.IntegerWidth(), pulseapp->prefs->mini_window_rect.IntegerHeight()); MoveTo(pulseapp->prefs->mini_window_rect.left, pulseapp->prefs->mini_window_rect.top); MoveOnScreen(); break; case PV_DESKBAR_MODE: // Do not set window's mode to DESKBAR_MODE because the // destructor needs to save the correct BRect. ~PulseApp() // will handle launching the replicant after our prefs are saved. pulseapp->prefs->window_mode = DESKBAR_MODE; PostMessage(B_QUIT_REQUESTED); break; } }
bool LoadInDeskbar() { PulseApp *pulseapp = (PulseApp *)be_app; BDeskbar *deskbar = new BDeskbar(); // Don't allow two copies in the Deskbar at once if (deskbar->HasItem("DeskbarPulseView")) { delete deskbar; return false; } // Must be 16 pixels high, the width is retrieved from the Prefs class int width = pulseapp->prefs->deskbar_icon_width; int min_width = GetMinimumViewWidth(); if (width < min_width) { pulseapp->prefs->deskbar_icon_width = min_width; width = min_width; } float height = deskbar->MaxItemHeight(); BRect rect(0, 0, width - 1, height - 1); DeskbarPulseView *replicant = new DeskbarPulseView(rect); status_t err = deskbar->AddItem(replicant); delete replicant; delete deskbar; if (err != B_OK) { BString message; snprintf(message.LockBuffer(512), 512, B_TRANSLATE("Installing in Deskbar failed\n%s"), strerror(err)); message.UnlockBuffer(); BAlert *alert = new BAlert(B_TRANSLATE("Error"), message.String(), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(NULL); return false; } return true; }
PulseApp::PulseApp(int argc, char **argv) : BApplication(APP_SIGNATURE) { prefs = new Prefs(); int mini = false, deskbar = false, normal = false; uint32 framecolor = 0, activecolor = 0, idlecolor = 0; while (1) { int option_index = 0; static struct option long_options[] = { {"deskbar", 0, &deskbar, true}, {"width", 1, 0, 'w'}, {"framecolor", 1, 0, 0}, {"activecolor", 1, 0, 0}, {"idlecolor", 1, 0, 0}, {"mini", 0, &mini, true}, {"normal", 0, &normal, true}, {"help", 0, 0, 'h'}, {0,0,0,0} }; int c = getopt_long(argc, argv, "hw:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: switch (option_index) { case 2: /* framecolor */ case 3: /* activecolor */ case 4: /* idlecolor */ uint32 rgb = strtoul(optarg, NULL, 0); rgb = rgb << 8; rgb |= 0x000000ff; switch (option_index) { case 2: framecolor = rgb; break; case 3: activecolor = rgb; break; case 4: idlecolor = rgb; break; } break; } break; case 'w': prefs->deskbar_icon_width = atoi(optarg); if (prefs->deskbar_icon_width < GetMinimumViewWidth()) prefs->deskbar_icon_width = GetMinimumViewWidth(); else if (prefs->deskbar_icon_width > 50) prefs->deskbar_icon_width = 50; break; case 'h': case '?': Usage(); break; default: printf("?? getopt returned character code 0%o ??\n", c); break; } } if (deskbar) { prefs->window_mode = DESKBAR_MODE; if (activecolor != 0) prefs->deskbar_active_color = activecolor; if (idlecolor != 0) prefs->deskbar_idle_color = idlecolor; if (framecolor != 0) prefs->deskbar_frame_color = framecolor; } else if (mini) { prefs->window_mode = MINI_WINDOW_MODE; if (activecolor != 0) prefs->mini_active_color = activecolor; if (idlecolor != 0) prefs->mini_idle_color = idlecolor; if (framecolor != 0) prefs->mini_frame_color = framecolor; } else if (normal) prefs->window_mode = NORMAL_WINDOW_MODE; prefs->Save(); BuildPulse(); }
Prefs::Prefs() : fFatalError(false) { BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Pulse_settings"); fFile = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE); if (fFile->InitCheck() != B_OK) { // try to open read-only if (fFile->SetTo(path.Path(), B_READ_ONLY) != B_OK) { fFatalError = true; return; } } int i = NORMAL_WINDOW_MODE; if (!GetInt("window_mode", &window_mode, &i)) { fFatalError = true; return; } // These three prefs require a connection to the app_server BRect r = GetNormalWindowRect(); if (!GetRect("normal_window_rect", &normal_window_rect, &r)) { fFatalError = true; return; } // While normal window position is under user control, size is not. // Width is fixed and height must be dynamically computed each time, // as number of CPUs could change since boot. ComputeNormalWindowSize(); r = GetMiniWindowRect(); if (!GetRect("mini_window_rect", &mini_window_rect, &r)) { fFatalError = true; return; } r.Set(100, 100, 415, 329); if (!GetRect("prefs_window_rect", &prefs_window_rect, &r)) { fFatalError = true; return; } i = DEFAULT_NORMAL_BAR_COLOR; if (!GetInt("normal_bar_color", &normal_bar_color, &i)) { fFatalError = true; return; } i = DEFAULT_MINI_ACTIVE_COLOR; if (!GetInt("mini_active_color", &mini_active_color, &i)) { fFatalError = true; return; } i = DEFAULT_MINI_IDLE_COLOR; if (!GetInt("mini_idle_color", &mini_idle_color, &i)) { fFatalError = true; return; } i = DEFAULT_MINI_FRAME_COLOR; if (!GetInt("mini_frame_color", &mini_frame_color, &i)) { fFatalError = true; return; } i = DEFAULT_DESKBAR_ACTIVE_COLOR; if (!GetInt("deskbar_active_color", &deskbar_active_color, &i)) { fFatalError = true; return; } i = DEFAULT_DESKBAR_IDLE_COLOR; if (!GetInt("deskbar_idle_color", &deskbar_idle_color, &i)) { fFatalError = true; return; } i = DEFAULT_DESKBAR_FRAME_COLOR; if (!GetInt("deskbar_frame_color", &deskbar_frame_color, &i)) { fFatalError = true; return; } bool b = DEFAULT_NORMAL_FADE_COLORS; if (!GetBool("normal_fade_colors", &normal_fade_colors, &b)) { fFatalError = 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 (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) { fFatalError = true; return; } }
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 (!GetInt("deskbar_icon_width", &deskbar_icon_width, &i)) { fatalerror = true; return; } }