Some changes to make it better fit into a Haiku distribution:

* Fixed Terminal signature to Haiku's Terminal.
* Removed documentation menu item.
* Minor cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17589 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-25 13:43:27 +00:00
parent 265fea4ad4
commit e2940ab6f0
4 changed files with 376 additions and 345 deletions
+47 -31
View File
@@ -1,9 +1,7 @@
/* /*
PCUtils.cpp PCUtils.cpp
ProcessController ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,36 +17,43 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCUtils.h" #include "PCUtils.h"
#include "PCWorld.h" #include "PCWorld.h"
#include "PCView.h" #include "PCView.h"
#include <string.h> #include "icons.data"
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h>
#include <Deskbar.h>
#include <FindDirectory.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Path.h> #include <Path.h>
#include <FindDirectory.h>
#include <Bitmap.h>
#include <Roster.h> #include <Roster.h>
#include <Deskbar.h>
#include <stdio.h>
#include "icons.data" #include <stdio.h>
#include <string.h>
#define snooze_time 1000000 #define snooze_time 1000000
team_id gAppServerTeamID = -1; team_id gAppServerTeamID = -1;
bool get_team_name_and_icon(infosPack & infopack, bool icon)
bool
get_team_name_and_icon(infosPack& infopack, bool icon)
{ {
if (gAppServerTeamID == -1 && strcmp (infopack.tminfo.args, "/boot/beos/system/servers/app_server") == 0) if (gAppServerTeamID == -1 && !strcmp(infopack.tminfo.args, "/boot/beos/system/servers/app_server"))
gAppServerTeamID = infopack.tminfo.team; gAppServerTeamID = infopack.tminfo.team;
bool nameFromArgs = false; bool nameFromArgs = false;
bool tryTrackerIcon = true; bool tryTrackerIcon = true;
for (int len = strlen(infopack.tminfo.args) - 1; len >= 0 && infopack.tminfo.args[len] == ' '; len--)
for (int len = strlen(infopack.tminfo.args) - 1; len >= 0 && infopack.tminfo.args[len] == ' '; len--) {
infopack.tminfo.args[len] = 0; infopack.tminfo.args[len] = 0;
}
app_info info; app_info info;
status_t status = be_roster->GetRunningAppInfo(infopack.tminfo.team, &info); status_t status = be_roster->GetRunningAppInfo(infopack.tminfo.team, &info);
if (status == B_OK || infopack.tminfo.team == B_SYSTEM_TEAM) { if (status == B_OK || infopack.tminfo.team == B_SYSTEM_TEAM) {
@@ -68,29 +73,36 @@ bool get_team_name_and_icon(infosPack & infopack, bool icon)
nameFromArgs = true; nameFromArgs = true;
tryTrackerIcon = (status == B_OK); tryTrackerIcon = (status == B_OK);
} }
strncpy(infopack.tmname, nameFromArgs ? infopack.tminfo.args : info.ref.name, B_PATH_NAME_LENGTH - 1);
strncpy(infopack.tmname, nameFromArgs ? infopack.tminfo.args : info.ref.name,
B_PATH_NAME_LENGTH - 1);
if (icon) { if (icon) {
infopack.tmicon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT); infopack.tmicon = new BBitmap(BRect(0, 0, 15, 15), B_COLOR_8_BIT);
if (!tryTrackerIcon || BNodeInfo::GetTrackerIcon(&info.ref, infopack.tmicon, B_MINI_ICON) != B_OK) if (!tryTrackerIcon || BNodeInfo::GetTrackerIcon(&info.ref, infopack.tmicon, B_MINI_ICON) != B_OK)
infopack.tmicon->SetBits(k_app_mini, 256, 0, B_COLOR_8_BIT); infopack.tmicon->SetBits(k_app_mini, 256, 0, B_COLOR_8_BIT);
} else } else
infopack.tmicon = NULL; infopack.tmicon = NULL;
return true; return true;
} }
bool launch (const char* signature, const char* path)
{ bool
status_t st = be_roster->Launch (signature); launch(const char* signature, const char* path)
if (st != B_OK && path)
{ {
status_t status = be_roster->Launch(signature);
if (status != B_OK && path) {
entry_ref ref; entry_ref ref;
if (get_ref_for_path(path, &ref) == B_OK) if (get_ref_for_path(path, &ref) == B_OK)
st = be_roster->Launch (&ref); status = be_roster->Launch(&ref);
} }
return (st == B_OK); return status == B_OK;
} }
void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float mix)
void
mix_colors(rgb_color &target, rgb_color & first, rgb_color & second, float mix)
{ {
target.red = (uint8)(second.red * mix + (1. - mix) * first.red); target.red = (uint8)(second.red * mix + (1. - mix) * first.red);
target.green = (uint8)(second.green * mix + (1. - mix) * first.green); target.green = (uint8)(second.green * mix + (1. - mix) * first.green);
@@ -98,30 +110,34 @@ void mix_colors (rgb_color &target, rgb_color & first, rgb_color & second, float
target.alpha = (uint8)(second.alpha * mix + (1. - mix) * first.alpha); target.alpha = (uint8)(second.alpha * mix + (1. - mix) * first.alpha);
} }
void find_self (entry_ref & ref)
void
find_self(entry_ref& ref)
{ {
int32 cookie = 0; int32 cookie = 0;
image_info info; image_info info;
while (get_next_image_info (0, &cookie, &info) == B_OK) while (get_next_image_info (0, &cookie, &info) == B_OK) {
{
if (((uint32) info.text <= (uint32) move_to_deskbar if (((uint32) info.text <= (uint32) move_to_deskbar
&& (uint32) info.text + (uint32) info.text_size > (uint32) move_to_deskbar) && (uint32) info.text + (uint32) info.text_size > (uint32) move_to_deskbar)
|| ((uint32) info.data <= (uint32) move_to_deskbar || ((uint32) info.data <= (uint32) move_to_deskbar
&& (uint32) info.data + (uint32) info.data_size > (uint32) move_to_deskbar)) && (uint32) info.data + (uint32) info.data_size > (uint32) move_to_deskbar)) {
{
if (get_ref_for_path (info.name, &ref) == B_OK) if (get_ref_for_path (info.name, &ref) == B_OK)
return; return;
} }
} }
// This works, but not always... :( // This works, but not always... :(
app_info ainfo; app_info appInfo;
be_roster->GetAppInfo (kSignature, &ainfo); be_roster->GetAppInfo(kSignature, &appInfo);
ref = ainfo.ref; ref = appInfo.ref;
} }
void move_to_deskbar (BDeskbar & db)
void
move_to_deskbar(BDeskbar& deskbar)
{ {
entry_ref ref; entry_ref ref;
find_self(ref); find_self(ref);
db.AddItem (&ref);
deskbar.AddItem(&ref);
} }
+108 -110
View File
@@ -84,16 +84,22 @@ typedef struct {
} Tdebug_thead_param; } Tdebug_thead_param;
extern "C" _EXPORT BView *instantiate_deskbar_item(void); extern "C" _EXPORT BView *instantiate_deskbar_item(void);
extern "C" _EXPORT BView *instantiate_deskbar_item(void)
extern "C" _EXPORT BView *
instantiate_deskbar_item(void)
{ {
gInDeskbar = true; gInDeskbar = true;
return new ProcessController(); return new ProcessController();
} }
ProcessController::ProcessController(BRect frame, bool temp) ProcessController::ProcessController(BRect frame, bool temp)
: BView(frame, kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW), : BView(frame, kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW),
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini), fProcessControllerIcon(kSignature),
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig), fProcessorIcon(k_cpu_mini),
fTrackerIcon(kTrackerSig),
fDeskbarIcon(kDeskbarSig),
fTerminalIcon(kTerminalSig),
fTemp(temp) fTemp(temp)
{ {
if (!temp) { if (!temp) {
@@ -106,37 +112,48 @@ ProcessController::ProcessController(BRect frame, bool temp)
} }
} }
ProcessController::ProcessController(BMessage *data):BView(data), ProcessController::ProcessController(BMessage *data)
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini), : BView(data),
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig), fProcessControllerIcon(kSignature),
fProcessorIcon(k_cpu_mini),
fTrackerIcon(kTrackerSig),
fDeskbarIcon(kDeskbarSig),
fTerminalIcon(kTerminalSig),
fTemp(false) fTemp(false)
{ {
Init(); Init();
} }
ProcessController::ProcessController() ProcessController::ProcessController()
: BView(BRect (0, 0, 15, 15), kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW), : BView(BRect (0, 0, 15, 15), kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW),
fProcessControllerIcon (kSignature), fProcessorIcon (k_cpu_mini), fProcessControllerIcon(kSignature),
fTrackerIcon (kTrackerSig), fDeskbarIcon (kDeskbarSig), fTerminalIcon (kTerminalSig), fProcessorIcon(k_cpu_mini),
fTrackerIcon(kTrackerSig),
fDeskbarIcon(kDeskbarSig),
fTerminalIcon(kTerminalSig),
fTemp(false) fTemp(false)
{ {
Init(); Init();
} }
ProcessController::~ProcessController() ProcessController::~ProcessController()
{ {
if (!fTemp) { if (!fTemp) {
if (gPopupThreadID) if (gPopupThreadID) {
{
status_t return_value; status_t return_value;
wait_for_thread (gPopupThreadID, &return_value); wait_for_thread (gPopupThreadID, &return_value);
} }
} }
delete fMessageRunner; delete fMessageRunner;
gPCView = NULL; gPCView = NULL;
} }
void ProcessController::Init()
void
ProcessController::Init()
{ {
gPCView = this; gPCView = this;
fMessageRunner = NULL; fMessageRunner = NULL;
@@ -147,14 +164,19 @@ void ProcessController::Init()
fPrevTime = 0; fPrevTime = 0;
} }
ProcessController *ProcessController::Instantiate(BMessage *data)
ProcessController *
ProcessController::Instantiate(BMessage *data)
{ {
if (!validate_instantiation(data, kClassName)) if (!validate_instantiation(data, kClassName))
return NULL; return NULL;
return new ProcessController(data); return new ProcessController(data);
} }
status_t ProcessController::Archive(BMessage *data, bool deep) const
status_t
ProcessController::Archive(BMessage *data, bool deep) const
{ {
BView::Archive(data, deep); BView::Archive(data, deep);
data->AddString("add_on", kSignature); data->AddString("add_on", kSignature);
@@ -162,7 +184,9 @@ status_t ProcessController::Archive(BMessage *data, bool deep) const
return B_OK; return B_OK;
} }
void ProcessController::MessageReceived(BMessage *message)
void
ProcessController::MessageReceived(BMessage *message)
{ {
team_id team; team_id team;
thread_id thread; thread_id thread;
@@ -256,37 +280,34 @@ void ProcessController::MessageReceived(BMessage *message)
{ {
if (!be_roster->IsRunning(kDeskbarSig)) if (!be_roster->IsRunning(kDeskbarSig))
launch(kDeskbarSig, "/boot/beos/system/Deskbar"); launch(kDeskbarSig, "/boot/beos/system/Deskbar");
BDeskbar db; BDeskbar deskbar;
if (gInDeskbar || db.HasItem (kDeskbarItemName)) if (gInDeskbar || deskbar.HasItem (kDeskbarItemName))
db.RemoveItem (kDeskbarItemName); deskbar.RemoveItem (kDeskbarItemName);
else else
move_to_deskbar (db); move_to_deskbar(deskbar);
}
break; break;
}
case 'CPU ': case 'CPU ':
{ {
int32 cpu; int32 cpu;
if (message->FindInt32 ("cpu", &cpu) == B_OK) if (message->FindInt32 ("cpu", &cpu) == B_OK) {
{
bool last = true; bool last = true;
for (int p = 0; p < gCPUcount; p++) for (int p = 0; p < gCPUcount; p++) {
if (p != cpu && _kget_cpu_state_ (p)) if (p != cpu && _kget_cpu_state_(p)) {
{
last = false; last = false;
break; break;
} }
if (last) }
{ if (last) {
alert = new BAlert("", "This is the last active processor...\nYou can't turn it off!", alert = new BAlert("", "This is the last active processor...\nYou can't turn it off!",
"That's no Fun!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); "That's no Fun!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go(); alert->Go();
} } else
else
_kset_cpu_state_(cpu, !_kget_cpu_state_(cpu)); _kset_cpu_state_(cpu, !_kget_cpu_state_(cpu));
} }
}
break; break;
}
case 'Colo': case 'Colo':
{ {
@@ -294,35 +315,8 @@ void ProcessController::MessageReceived(BMessage *message)
gMimicPulse = (gMimicPulse == 0); gMimicPulse = (gMimicPulse == 0);
tPreferences.SaveInt32(gMimicPulse, kMimicPulsePref); tPreferences.SaveInt32(gMimicPulse, kMimicPulsePref);
DefaultColors(); DefaultColors();
}
break; break;
case 'Docu':
{
entry_ref ref;
find_self (ref);
BEntry entry (&ref);
BDirectory parent;
entry.GetParent (&parent);
entry.SetTo (&parent, "ProcessController's Doc/ProcessController's Notice.html");
BPath path (&entry);
if (path.InitCheck () == B_OK)
{
char url[B_PATH_NAME_LENGTH + 64];
sprintf (url, "file://%s", path.Path ());
char* argv[2];
argv[0] = url;
argv[1] = 0;
be_roster->Launch ("text/html", 1, argv);
} }
else
{
alert = new BAlert("", "ProcessController's documentation could not be found. You may want to reinstall ProcessController...",
"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go ();
}
}
break;
case B_ABOUT_REQUESTED: case B_ABOUT_REQUESTED:
new AboutPC(BScreen().Frame()); new AboutPC(BScreen().Frame());
@@ -333,29 +327,28 @@ void ProcessController::MessageReceived(BMessage *message)
} }
} }
void ProcessController::DefaultColors ()
void
ProcessController::DefaultColors()
{ {
swap_color.red = 203; swap_color.red = 203;
swap_color.green = 0; swap_color.green = 0;
swap_color.blue = 0; swap_color.blue = 0;
swap_color.alpha = 255; swap_color.alpha = 255;
bool set = false; bool set = false;
if (gMimicPulse)
{ if (gMimicPulse) {
BPath prefpath; BPath prefpath;
if (find_directory (B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath) == B_OK) {
{
BDirectory prefdir(prefpath.Path ()); BDirectory prefdir(prefpath.Path ());
BEntry entry; BEntry entry;
prefdir.FindEntry (kPuseSettings, &entry); prefdir.FindEntry (kPuseSettings, &entry);
BFile file(&entry, B_READ_ONLY); BFile file(&entry, B_READ_ONLY);
if (file.InitCheck() == B_OK) if (file.InitCheck() == B_OK) {
{
int32 f, i, a; int32 f, i, a;
if (file.ReadAttr(kFrameColorPref, B_INT32_TYPE, 0, &f, 4) == 4 && if (file.ReadAttr(kFrameColorPref, B_INT32_TYPE, 0, &f, 4) == 4
file.ReadAttr(kActiveColorPref, B_INT32_TYPE, 0, &a, 4) == 4 && && file.ReadAttr(kActiveColorPref, B_INT32_TYPE, 0, &a, 4) == 4
file.ReadAttr(kIdleColorPref, B_INT32_TYPE, 0, &i, 4) == 4) && file.ReadAttr(kIdleColorPref, B_INT32_TYPE, 0, &i, 4) == 4) {
{
active_color.red = (a & 0xff000000) >> 24; active_color.red = (a & 0xff000000) >> 24;
active_color.green = (a & 0x00ff0000) >> 16; active_color.green = (a & 0x00ff0000) >> 16;
active_color.blue = (a & 0x0000ff00) >> 8; active_color.blue = (a & 0x0000ff00) >> 8;
@@ -374,24 +367,20 @@ void ProcessController::DefaultColors ()
mix_colors (memory_color, active_color, swap_color, 0.8); mix_colors (memory_color, active_color, swap_color, 0.8);
set = true; set = true;
} } else {
else
{
BAlert * alert = new BAlert("", "I couldn't read Pulse's preferences...", BAlert * alert = new BAlert("", "I couldn't read Pulse's preferences...",
"Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); "Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go (); alert->Go ();
} }
} } else {
else
{
BAlert * alert = new BAlert("", "I couldn't find Pulse's preferences...", BAlert * alert = new BAlert("", "I couldn't find Pulse's preferences...",
"Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); "Sorry!", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go (); alert->Go ();
} }
} }
} }
if (!set)
{ if (!set) {
active_color = kKernelBlue; active_color = kKernelBlue;
active_color = tint_color (active_color, B_LIGHTEN_2_TINT); active_color = tint_color (active_color, B_LIGHTEN_2_TINT);
idle_color = active_color; idle_color = active_color;
@@ -404,13 +393,16 @@ void ProcessController::DefaultColors ()
// idle_color = kWhite; // idle_color = kWhite;
} }
void ProcessController::AttachedToWindow ()
void
ProcessController::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
if (Parent()) if (Parent())
SetViewColor(B_TRANSPARENT_COLOR); SetViewColor(B_TRANSPARENT_COLOR);
else else
SetViewColor(kBlack); SetViewColor(kBlack);
GebsPreferences tPreferences(kPreferencesFileName, NULL, false); GebsPreferences tPreferences(kPreferencesFileName, NULL, false);
tPreferences.ReadInt32(gMimicPulse, kMimicPulsePref); tPreferences.ReadInt32(gMimicPulse, kMimicPulsePref);
DefaultColors(); DefaultColors();
@@ -434,11 +426,13 @@ void ProcessController::AttachedToWindow ()
else else
gMenuBackColorSelected = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR); // Dano & up gMenuBackColorSelected = ui_color(B_MENU_SELECTION_BACKGROUND_COLOR); // Dano & up
gWhiteSelected = tint_color(kWhite, B_HIGHLIGHT_BACKGROUND_TINT); gWhiteSelected = tint_color(kWhite, B_HIGHLIGHT_BACKGROUND_TINT);
BMessenger messenger (this); BMessenger messenger (this);
BMessage message ('Puls'); BMessage message ('Puls');
fMessageRunner = new BMessageRunner (messenger, &message, 250000, -1); fMessageRunner = new BMessageRunner (messenger, &message, 250000, -1);
} }
typedef struct { typedef struct {
float cpu_width; float cpu_width;
float cpu_inter; float cpu_inter;
@@ -456,13 +450,17 @@ layoutT layout[] = {
{ 1, 1, 1 }, { 1, 1, 1 },
{ 1, 0, 3 } }; // 8 { 1, 0, 3 } }; // 8
void ProcessController::Draw(BRect)
void
ProcessController::Draw(BRect)
{ {
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
DoDraw(true); DoDraw(true);
} }
void ProcessController::DoDraw (bool force)
void
ProcessController::DoDraw(bool force)
{ {
//gCPUcount = 1; //gCPUcount = 1;
BRect bounds(Bounds()); BRect bounds(Bounds());
@@ -473,14 +471,12 @@ void ProcessController::DoDraw (bool force)
float bar_width = layout[gCPUcount].cpu_width; float bar_width = layout[gCPUcount].cpu_width;
// interspace // interspace
float right = left + gCPUcount * (bar_width + layout[gCPUcount].cpu_inter) - layout[gCPUcount].cpu_inter; // right of CPU frame... float right = left + gCPUcount * (bar_width + layout[gCPUcount].cpu_inter) - layout[gCPUcount].cpu_inter; // right of CPU frame...
if (force && Parent ()) if (force && Parent()) {
{
SetHighColor (Parent ()->ViewColor ()); SetHighColor (Parent ()->ViewColor ());
FillRect (BRect (right + 1, top - 1, right + 2, bottom + 1)); FillRect (BRect (right + 1, top - 1, right + 2, bottom + 1));
} }
if (force) if (force) {
{
SetHighColor (frame_color); SetHighColor (frame_color);
StrokeRect (BRect (left - 1, top - 1, right, bottom + 1)); StrokeRect (BRect (left - 1, top - 1, right, bottom + 1));
if (gCPUcount == 2) if (gCPUcount == 2)
@@ -490,8 +486,7 @@ void ProcessController::DoDraw (bool force)
if (force) if (force)
StrokeRect (BRect (leftMem - 1, top - 1, leftMem + layout[gCPUcount].mem_width, bottom + 1)); StrokeRect (BRect (leftMem - 1, top - 1, leftMem + layout[gCPUcount].mem_width, bottom + 1));
for (int x = 0; x < gCPUcount; x++) for (int x = 0; x < gCPUcount; x++) {
{
right = left + bar_width - 1; right = left + bar_width - 1;
float rem = fCPUTimes[x] * (h + 1); float rem = fCPUTimes[x] * (h + 1);
float bar_height = floorf (rem); float bar_height = floorf (rem);
@@ -501,13 +496,11 @@ void ProcessController::DoDraw (bool force)
float idle_top = top; float idle_top = top;
if (!force && previous_limit > top) if (!force && previous_limit > top)
idle_top = previous_limit - 1; idle_top = previous_limit - 1;
if (limit > idle_top) if (limit > idle_top) {
{
SetHighColor (idle_color); SetHighColor (idle_color);
FillRect (BRect (left, idle_top, right, limit - 1)); FillRect (BRect (left, idle_top, right, limit - 1));
} }
if (bar_height <= h) if (bar_height <= h) {
{
rgb_color fraction_color; rgb_color fraction_color;
mix_colors (fraction_color, idle_color, active_color, rem); mix_colors (fraction_color, idle_color, active_color, rem);
SetHighColor (fraction_color); SetHighColor (fraction_color);
@@ -516,8 +509,7 @@ void ProcessController::DoDraw (bool force)
float active_bottom = bottom; float active_bottom = bottom;
if (!force && previous_limit < bottom) if (!force && previous_limit < bottom)
active_bottom = previous_limit + 1; active_bottom = previous_limit + 1;
if (limit < active_bottom) if (limit < active_bottom) {
{
SetHighColor(active_color); SetHighColor(active_color);
FillRect(BRect(left, limit + 1, right, active_bottom)); FillRect(BRect(left, limit + 1, right, active_bottom));
} }
@@ -540,13 +532,11 @@ void ProcessController::DoDraw (bool force)
float free_top = top; float free_top = top;
if (!force && previous_limit > top) if (!force && previous_limit > top)
free_top = previous_limit - 1; free_top = previous_limit - 1;
if (limit > free_top) if (limit > free_top) {
{
SetHighColor (idle_color); SetHighColor (idle_color);
FillRect (BRect (leftMem, free_top, rightMem, limit - 1)); FillRect (BRect (leftMem, free_top, rightMem, limit - 1));
} }
if (bar_height <= h) if (bar_height <= h) {
{
rgb_color fraction_color; rgb_color fraction_color;
mix_colors (fraction_color, idle_color, used_memory_color, rem); mix_colors (fraction_color, idle_color, used_memory_color, rem);
SetHighColor (fraction_color); SetHighColor (fraction_color);
@@ -555,15 +545,17 @@ void ProcessController::DoDraw (bool force)
float used_bottom = bottom; float used_bottom = bottom;
// if (!force && previous_limit < bottom) // if (!force && previous_limit < bottom)
// used_bottom = previous_limit + 1; // used_bottom = previous_limit + 1;
if (limit < used_bottom) if (limit < used_bottom) {
{
SetHighColor (used_memory_color); SetHighColor (used_memory_color);
FillRect (BRect (leftMem, limit + 1, rightMem, used_bottom)); FillRect (BRect (leftMem, limit + 1, rightMem, used_bottom));
} }
fLastMemoryHeight = bar_height; fLastMemoryHeight = bar_height;
} }
void ProcessController::Update () {
void
ProcessController::Update()
{
system_info sys_info; system_info sys_info;
get_system_info(&sys_info); get_system_info(&sys_info);
bigtime_t now = system_time(); bigtime_t now = system_time();
@@ -584,14 +576,18 @@ void ProcessController::Update () {
fPrevTime = now; fPrevTime = now;
} }
long thread_quit_application(void *arg)
long
thread_quit_application(void *arg)
{ {
BMessenger messenger (NULL, (team_id) arg); BMessenger messenger (NULL, (team_id) arg);
messenger.SendMessage (B_QUIT_REQUESTED); messenger.SendMessage (B_QUIT_REQUESTED);
return B_OK; return B_OK;
} }
long thread_debug_thread (void *arg)
long
thread_debug_thread(void *arg)
{ {
Tdebug_thead_param* param = (Tdebug_thead_param*) arg; Tdebug_thead_param* param = (Tdebug_thead_param*) arg;
thread_info thinfo; thread_info thinfo;
@@ -602,34 +598,36 @@ long thread_debug_thread (void *arg)
if (param->sem >= 0 && thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem) { if (param->sem >= 0 && thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem) {
snooze(1000000); snooze(1000000);
get_thread_info(param->thread, &thinfo); get_thread_info(param->thread, &thinfo);
if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time) if (thinfo.state == B_THREAD_WAITING
{ && param->sem == thinfo.sem
&& param->totalTime == thinfo.user_time + thinfo.kernel_time) {
// the thread has been waiting for this semaphore since the before the alert, not doing anything... Let's push it out of there! // the thread has been waiting for this semaphore since the before the alert, not doing anything... Let's push it out of there!
sem_info sinfo; sem_info sinfo;
thread_info thinfo; thread_info thinfo;
infosPack infos; infosPack infos;
if (get_sem_info (param->sem, &sinfo) == B_OK && get_thread_info (param->thread, &thinfo) == B_OK && get_team_info (thinfo.team, &infos.tminfo) == B_OK)
{ if (get_sem_info(param->sem, &sinfo) == B_OK
&& get_thread_info(param->thread, &thinfo) == B_OK
&& get_team_info(thinfo.team, &infos.tminfo) == B_OK) {
sprintf (texte, "This thread is waiting for the semaphore called \"%s\". As long as it waits for this semaphore, " sprintf (texte, "This thread is waiting for the semaphore called \"%s\". As long as it waits for this semaphore, "
"you won't be able to debug that thread.\n", sinfo.name); "you won't be able to debug that thread.\n", sinfo.name);
if (sinfo.team == thinfo.team) if (sinfo.team == thinfo.team)
strcat (texte, "This semaphore belongs to the thread's team.\n\nShould I release this semaphore?\n"); strcat (texte, "This semaphore belongs to the thread's team.\n\nShould I release this semaphore?\n");
else else {
{
get_team_name_and_icon (infos); get_team_name_and_icon (infos);
char moretexte[1024]; char moretexte[1024];
sprintf (moretexte, "\nWARNING! This semaphore belongs to the team \"%s\"!\n\nShould I release this semaphore anyway?\n", infos.tmname); sprintf (moretexte, "\nWARNING! This semaphore belongs to the team \"%s\"!\n\nShould I release this semaphore anyway?\n", infos.tmname);
strcat (texte, moretexte); strcat (texte, moretexte);
} }
BAlert* alert = new BAlert("", texte, "Cancel", "Release", NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
BAlert* alert = new BAlert("", texte, "Cancel", "Release", NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetShortcut(0, B_ESCAPE); alert->SetShortcut(0, B_ESCAPE);
if (alert->Go()) if (alert->Go()) {
{
get_thread_info (param->thread, &thinfo); get_thread_info (param->thread, &thinfo);
if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time) if (thinfo.state == B_THREAD_WAITING && param->sem == thinfo.sem && param->totalTime == thinfo.user_time + thinfo.kernel_time)
release_sem(param->sem); release_sem(param->sem);
else else {
{
alert = new BAlert("", "The semaphore wasn't released, because it wasn't necessary anymore!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert = new BAlert("", "The semaphore wasn't released, because it wasn't necessary anymore!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go(); alert->Go();
} }
+48 -41
View File
@@ -1,9 +1,7 @@
/* /*
PCView2.cpp PCView2.cpp
ProcessController ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,28 +17,31 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCView.h" #include "PCView.h"
#include "QuitMenu.h"
#include "AutoIcon.h"
#include "IconMenuItem.h" #include "IconMenuItem.h"
#include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h"
#include "PCUtils.h"
#include "PCWorld.h"
#include "Preferences.h"
#include "QuitMenu.h"
#include "TeamBarMenu.h" #include "TeamBarMenu.h"
#include "TeamBarMenuItem.h" #include "TeamBarMenuItem.h"
#include "ThreadBarMenu.h" #include "ThreadBarMenu.h"
#include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h"
#include "PCWorld.h"
#include "Preferences.h"
#include "PCUtils.h"
#include "AutoIcon.h"
#include <Screen.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Roster.h>
#include <PopUpMenu.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <PopUpMenu.h>
#include <Roster.h>
#include <Screen.h>
#include <stdio.h> #include <stdio.h>
#define addtopbottom(x) if (top) popup->AddItem(x); else popup->AddItem(x, 0) #define addtopbottom(x) if (top) popup->AddItem(x); else popup->AddItem(x, 0)
long thread_popup(void *arg); long thread_popup(void *arg);
@@ -54,45 +55,54 @@ typedef struct {
bool top; bool top;
} Tpopup_param; } Tpopup_param;
void ProcessController::MouseDown(BPoint where)
void
ProcessController::MouseDown(BPoint where)
{ {
if (atomic_add (&gPopupFlag, 1) > 0) { if (atomic_add (&gPopupFlag, 1) > 0) {
atomic_add (&gPopupFlag, -1); atomic_add (&gPopupFlag, -1);
return; return;
} }
Tpopup_param* param = new Tpopup_param; Tpopup_param* param = new Tpopup_param;
ConvertToScreen(&where); ConvertToScreen(&where);
param->where = where; param->where = where;
param->clickToOpenRect = Frame (); param->clickToOpenRect = Frame ();
ConvertToScreen (&param->clickToOpenRect); ConvertToScreen (&param->clickToOpenRect);
param->top = where.y < BScreen(this->Window()).Frame().bottom-50; param->top = where.y < BScreen(this->Window()).Frame().bottom-50;
gPopupThreadID = spawn_thread(thread_popup, "Popup holder thread", B_URGENT_DISPLAY_PRIORITY, param);
gPopupThreadID = spawn_thread(thread_popup, "Popup holder thread",
B_URGENT_DISPLAY_PRIORITY, param);
resume_thread(gPopupThreadID); resume_thread(gPopupThreadID);
} }
long thread_popup(void *arg)
long
thread_popup(void *arg)
{ {
Tpopup_param* param = (Tpopup_param*) arg; Tpopup_param* param = (Tpopup_param*) arg;
system_info sinfo;
int32 mcookie, hcookie; int32 mcookie, hcookie;
long m, h; long m, h;
BMenuItem* item; BMenuItem* item;
bool top = param->top; bool top = param->top;
get_system_info(&sinfo); system_info systemInfo;
infosPack *infos = new infosPack[sinfo.used_teams]; get_system_info(&systemInfo);
for (m = 0, mcookie = 0; m < sinfo.used_teams; m++) { infosPack* infos = new infosPack[systemInfo.used_teams];
// TODO: this doesn't necessarily get all teams
for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
infos[m].tmicon = NULL; infos[m].tmicon = NULL;
infos[m].tmname[0] = 0; infos[m].tmname[0] = 0;
infos[m].thinfo = NULL; infos[m].thinfo = NULL;
if (get_next_team_info(&mcookie, &infos[m].tminfo) == B_OK) { if (get_next_team_info(&mcookie, &infos[m].tminfo) == B_OK) {
infos[m].thinfo = new thread_info[infos[m].tminfo.thread_count]; infos[m].thinfo = new thread_info[infos[m].tminfo.thread_count];
for (h = 0, hcookie = 0; h < infos[m].tminfo.thread_count; h++) for (h = 0, hcookie = 0; h < infos[m].tminfo.thread_count; h++) {
if (get_next_thread_info(infos[m].tminfo.team, &hcookie, &infos[m].thinfo[h]) != B_OK) if (get_next_thread_info(infos[m].tminfo.team, &hcookie, &infos[m].thinfo[h]) != B_OK)
infos[m].thinfo[h].thread = -1; infos[m].thinfo[h].thread = -1;
}
get_team_name_and_icon(infos[m], true); get_team_name_and_icon(infos[m], true);
} else { } else {
sinfo.used_teams = m; systemInfo.used_teams = m;
infos[m].tminfo.team = -1; infos[m].tminfo.team = -1;
} }
} }
@@ -101,25 +111,26 @@ long thread_popup(void *arg)
popup->SetFont(be_plain_font); popup->SetFont(be_plain_font);
// Quit section // Quit section
BMenu* QuitPopup = new QuitMenu ("Quit an Application", infos, sinfo.used_teams); BMenu* QuitPopup = new QuitMenu("Quit an Application", infos, systemInfo.used_teams);
QuitPopup->SetFont(be_plain_font); QuitPopup->SetFont(be_plain_font);
popup->AddItem(QuitPopup); popup->AddItem(QuitPopup);
// Memory Usage section // Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu ("Spy Memory Usage", infos, &sinfo); MemoryBarMenu* MemoryPopup = new MemoryBarMenu("Spy Memory Usage", infos, &systemInfo);
int commitedMemory = int (sinfo.used_pages * B_PAGE_SIZE / 1024); int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
for (m = 0; m < sinfo.used_teams; m++) for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) if (infos[m].tminfo.team >= 0) {
{
MemoryBarMenuItem* memoryItem = new MemoryBarMenuItem(infos[m].tmname, infos[m].tminfo.team, infos[m].tmicon, false, NULL); MemoryBarMenuItem* memoryItem = new MemoryBarMenuItem(infos[m].tmname, infos[m].tminfo.team, infos[m].tmicon, false, NULL);
MemoryPopup->AddItem(memoryItem); MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(commitedMemory); memoryItem->UpdateSituation(commitedMemory);
} }
}
addtopbottom(MemoryPopup); addtopbottom(MemoryPopup);
// CPU Load section // CPU Load section
TeamBarMenu* CPUPopup = new TeamBarMenu ("Kill, Debug, or Change Priority", infos, sinfo.used_teams); TeamBarMenu* CPUPopup = new TeamBarMenu("Kill, Debug, or Change Priority", infos, systemInfo.used_teams);
for (m = 0; m < sinfo.used_teams; m++) { for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) { if (infos[m].tminfo.team >= 0) {
ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].tmname, infos[m].tminfo.team, infos[m].tminfo.thread_count); ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].tmname, infos[m].tminfo.team, infos[m].tminfo.thread_count);
BMessage* kill_team = new BMessage('KlTm'); BMessage* kill_team = new BMessage('KlTm');
@@ -129,14 +140,13 @@ long thread_popup(void *arg)
CPUPopup->AddItem(item); CPUPopup->AddItem(item);
} }
} }
addtopbottom(CPUPopup); addtopbottom(CPUPopup);
addtopbottom(new BSeparatorItem()); addtopbottom(new BSeparatorItem());
// CPU on/off section // CPU on/off section
if (gCPUcount > 1) if (gCPUcount > 1) {
{ for (int i = 0; i < gCPUcount; i++) {
for (int i = 0; i < gCPUcount; i++)
{
char item_name[32]; char item_name[32];
sprintf (item_name, "Processor %d", i + 1); sprintf (item_name, "Processor %d", i + 1);
BMessage* m = new BMessage ('CPU '); BMessage* m = new BMessage ('CPU ');
@@ -180,13 +190,10 @@ long thread_popup(void *arg)
item->SetMarked (gMimicPulse); item->SetMarked (gMimicPulse);
addtopbottom (item); addtopbottom (item);
item = new BMenuItem("Read Documentation", new BMessage ('Docu'));
item->SetTarget (gPCView);
addtopbottom (item);
addtopbottom(new BSeparatorItem ()); addtopbottom(new BSeparatorItem ());
item = new IconMenuItem (gPCView->fProcessControllerIcon, "About ProcessController", new BMessage(B_ABOUT_REQUESTED)); item = new IconMenuItem(gPCView->fProcessControllerIcon, "About ProcessController",
new BMessage(B_ABOUT_REQUESTED));
item->SetTarget(gPCView); item->SetTarget(gPCView);
addtopbottom(item); addtopbottom(item);
@@ -195,7 +202,7 @@ long thread_popup(void *arg)
popup->Go(param->where, true, true, param->clickToOpenRect); popup->Go(param->where, true, true, param->clickToOpenRect);
delete popup; delete popup;
for (m = 0; m < sinfo.used_teams; m++) { for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].tminfo.team >= 0) { if (infos[m].tminfo.team >= 0) {
delete[] infos[m].thinfo; delete[] infos[m].thinfo;
delete infos[m].tmicon; delete infos[m].tmicon;
+47 -37
View File
@@ -1,9 +1,7 @@
/* /*
PCWorld.cpp PCWorld.cpp
ProcessController ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,57 +17,57 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCWorld.h" #include "PCWorld.h"
#include "PCWindow.h" #include "PCWindow.h"
#include "PCView.h" #include "PCView.h"
#include "PCUtils.h" #include "PCUtils.h"
#include <stdio.h>
#include <stdlib.h>
#include <Roster.h> #include <Roster.h>
#include <Deskbar.h> #include <Deskbar.h>
#include <stdio.h>
#include <stdlib.h>
const char* kSignature = "application/x-vnd.Geb-ProcessController"; const char* kSignature = "application/x-vnd.Geb-ProcessController";
const char* kTrackerSig = "application/x-vnd.Be-TRAK"; const char* kTrackerSig = "application/x-vnd.Be-TRAK";
const char* kDeskbarSig = "application/x-vnd.Be-TSKB"; const char* kDeskbarSig = "application/x-vnd.Be-TSKB";
const char *kTerminalSig = "application/x-vnd.Be-SHEL"; const char* kTerminalSig = "application/x-vnd.Haiku-Terminal";
const char* kPreferencesFileName = "ProcessController Prefs"; const char* kPreferencesFileName = "ProcessController Prefs";
thread_id id = 0; thread_id id = 0;
int main()
{
PCApplication application;
application.Run();
return B_OK; PCApplication::PCApplication()
} : BApplication(kSignature)
PCApplication::PCApplication():BApplication(kSignature)
{ {
} }
PCApplication::~PCApplication() PCApplication::~PCApplication()
{ {
status_t thread_return_value;
if (id) { if (id) {
wait_for_thread(id, &thread_return_value); status_t returnValue;
id = 0; wait_for_thread(id, &returnValue);
} }
} }
void PCApplication::ReadyToRun ()
void
PCApplication::ReadyToRun()
{ {
new PCWindow(); new PCWindow();
// quitter les autres ProcessController eventuels...
// quit other eventually running instances
BList list; BList list;
be_roster->GetAppList(kSignature, &list); be_roster->GetAppList(kSignature, &list);
long pc_count = list.CountItems (); long count = list.CountItems();
if (pc_count > 1) { if (count > 1) {
for (long k = 0; k < pc_count-1; k++) { for (long i = 0; i < count - 1; i++) {
BMessenger* otherme = new BMessenger (NULL, (team_id) list.ItemAt (k)); BMessenger* otherme = new BMessenger(NULL, (team_id)list.ItemAt(i));
BMessage* message = new BMessage(B_QUIT_REQUESTED); BMessage* message = new BMessage(B_QUIT_REQUESTED);
otherme->SendMessage(message); otherme->SendMessage(message);
delete otherme; delete otherme;
@@ -77,13 +75,13 @@ void PCApplication::ReadyToRun ()
} }
} }
void PCApplication::ArgvReceived (int32 argc, char **argv)
{ void
if (argc == 2 && strcmp (argv[1], "-desktop-reset") == 0) PCApplication::ArgvReceived (int32 argc, char **argv)
{ {
if (argc == 2 && strcmp(argv[1], "-desktop-reset") == 0) {
team_id tracker = be_roster->TeamFor(kTrackerSig); team_id tracker = be_roster->TeamFor(kTrackerSig);
if (tracker >= 0) if (tracker >= 0) {
{
BMessenger messenger(NULL, tracker); BMessenger messenger(NULL, tracker);
messenger.SendMessage(B_QUIT_REQUESTED); messenger.SendMessage(B_QUIT_REQUESTED);
int k = 500; int k = 500;
@@ -93,17 +91,29 @@ void PCApplication::ArgvReceived (int32 argc, char **argv)
} }
remove("/boot/home/config/settings/Tracker/tracker_shelf"); remove("/boot/home/config/settings/Tracker/tracker_shelf");
launch(kTrackerSig, "/boot/beos/system/Tracker"); launch(kTrackerSig, "/boot/beos/system/Tracker");
} } else if (argc == 2 && strcmp(argv[1], "-deskbar") == 0) {
else if (argc == 2 && strcmp (argv[1], "-deskbar") == 0) BDeskbar deskbar;
{ if (!gInDeskbar && !deskbar.HasItem(kDeskbarItemName))
BDeskbar db; move_to_deskbar(deskbar);
if (!gInDeskbar && !db.HasItem (kDeskbarItemName)) } else if (argc > 1) {
move_to_deskbar (db);
}
else if (argc > 1) {
// print a simple usage string // print a simple usage string
printf( "Usage: %s [-deskbar]\n", argv[0]); printf( "Usage: %s [-deskbar]\n", argv[0]);
printf( "(c) 1997-2001 Georges-Edouard Berenger, [email protected]\n"); printf( "(c) 1997-2001 Georges-Edouard Berenger, [email protected]\n");
} }
Quit(); Quit();
} }
// #pragma mark -
int
main()
{
PCApplication application;
application.Run();
return B_OK;
}