2 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
3 Copyright (C) 2004 beunited.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "Utilities.h"
23 #include "ProcessController.h"
30 #include <FindDirectory.h>
42 get_team_name_and_icon(info_pack
& infoPack
, bool icon
)
45 find_directory(B_BEOS_SYSTEM_DIRECTORY
, &systemPath
);
47 bool nameFromArgs
= false;
48 bool tryTrackerIcon
= true;
50 for (int len
= strlen(infoPack
.team_info
.args
) - 1;
51 len
>= 0 && infoPack
.team_info
.args
[len
] == ' '; len
--) {
52 infoPack
.team_info
.args
[len
] = 0;
56 status_t status
= be_roster
->GetRunningAppInfo(infoPack
.team_info
.team
, &info
);
58 if (infoPack
.team_info
.team
== B_SYSTEM_TEAM
) {
59 // Get icon and name from kernel image
60 system_info systemInfo
;
61 get_system_info(&systemInfo
);
63 BPath
kernelPath(systemPath
);
64 kernelPath
.Append(systemInfo
.kernel_name
);
65 get_ref_for_path(kernelPath
.Path(), &info
.ref
);
68 status
= BPrivate::get_app_ref(infoPack
.team_info
.team
, &info
.ref
);
70 tryTrackerIcon
= (status
== B_OK
);
74 strncpy(infoPack
.team_name
, nameFromArgs
? infoPack
.team_info
.args
: info
.ref
.name
,
75 B_PATH_NAME_LENGTH
- 1);
78 infoPack
.team_icon
= new BBitmap(BRect(0, 0, 15, 15), B_RGBA32
);
80 || BNodeInfo::GetTrackerIcon(&info
.ref
, infoPack
.team_icon
,
81 B_MINI_ICON
) != B_OK
) {
82 BMimeType
genericAppType(B_APP_MIME_TYPE
);
83 status
= genericAppType
.GetIcon(infoPack
.team_icon
, B_MINI_ICON
);
86 infoPack
.team_icon
= NULL
;
93 launch(const char* signature
, const char* path
)
95 status_t status
= be_roster
->Launch(signature
);
96 if (status
!= B_OK
&& path
) {
98 if (get_ref_for_path(path
, &ref
) == B_OK
)
99 status
= be_roster
->Launch(&ref
);
101 return status
== B_OK
;
106 mix_colors(rgb_color
&target
, rgb_color
& first
, rgb_color
& second
, float mix
)
108 target
.red
= (uint8
)(second
.red
* mix
+ (1. - mix
) * first
.red
);
109 target
.green
= (uint8
)(second
.green
* mix
+ (1. - mix
) * first
.green
);
110 target
.blue
= (uint8
)(second
.blue
* mix
+ (1. - mix
) * first
.blue
);
111 target
.alpha
= (uint8
)(second
.alpha
* mix
+ (1. - mix
) * first
.alpha
);
116 find_self(entry_ref
& ref
)
120 while (get_next_image_info (0, &cookie
, &info
) == B_OK
) {
121 if (((addr_t
)info
.text
<= (addr_t
)move_to_deskbar
122 && (addr_t
)info
.text
+ (size_t)info
.text_size
> (addr_t
)move_to_deskbar
)
123 || ((addr_t
)info
.data
<= (addr_t
)move_to_deskbar
124 && (addr_t
)info
.data
+ (size_t)info
.data_size
> (addr_t
)move_to_deskbar
)) {
125 if (get_ref_for_path (info
.name
, &ref
) == B_OK
)
130 // This works, but not always... :(
132 be_roster
->GetAppInfo(kSignature
, &appInfo
);
138 move_to_deskbar(BDeskbar
& deskbar
)
143 deskbar
.AddItem(&ref
);
148 make_window_visible(BWindow
* window
, bool mayResize
)
150 uint32 flags
= window
->Flags();
151 BRect screen
= BScreen(window
).Frame();
152 BRect frame
= window
->Frame();
153 screen
.InsetBy(4, 8);
154 screen
.OffsetBy(0, 8);
157 float width
= frame
.Width();
158 float height
= frame
.Height();
159 if (screen
.Width() < width
&& !(flags
& B_NOT_H_RESIZABLE
))
160 width
= screen
.Width();
161 if (screen
.Height() < height
&& !(flags
& B_NOT_V_RESIZABLE
))
162 height
= screen
.Height();
163 if (width
!= frame
.Width() || height
!= frame
.Height()) {
164 window
->ResizeTo(width
, height
);
165 frame
.right
= frame
.left
+ width
;
166 frame
.bottom
= frame
.top
+ height
;
169 if (frame
.right
> screen
.right
)
170 window
->MoveBy(screen
.right
-frame
.right
, 0);
171 if (frame
.bottom
> screen
.bottom
)
172 window
->MoveBy(0, screen
.bottom
-frame
.bottom
);
173 if (frame
.left
< screen
.left
)
174 window
->MoveTo(screen
.left
, frame
.top
);
175 if (frame
.top
< screen
.top
)
176 window
->MoveBy(0, screen
.top
-frame
.top
);