apps/autoraise Restore functionality

* Restore functionality / compilation
		(C++11)Spacing issues with string macros fixed.
		Fix type declarartion for removeFromDeskbar so compiles
		on x86_64.

	* Code format cleanup

	* Remove DANO related code

Change-Id: I738d14914e320b7606210d8263065187b2c06b1a
Reviewed-on: https://review.haiku-os.org/c/898
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Rob Gill
2019-02-03 18:03:50 +00:00
committed by waddlesplash
parent 3493fcb668
commit b073a8c83f
6 changed files with 79 additions and 195 deletions
+30 -22
View File
@@ -6,15 +6,16 @@ AutoRaiseApp::AutoRaiseApp()
{
removeFromDeskbar(NULL);
_directToDeskbar = false;
//since the tray item shows an icon, and the class TrayView needs to be able to know the location
//of the executing binary, we write into the settings file this critical information when the app is fired up
//since the tray item shows an icon, and the class TrayView needs to be
//able to know the location of the executing binary, we write into the
//settings file this critical information when the app is fired up
app_info info;
be_app->GetAppInfo(&info);
//now, put the path into the settings file
AutoRaiseSettings settings;
settings.SetAppPath(info.ref);
settings.SetAppPath(info.ref);
}
AutoRaiseApp::~AutoRaiseApp()
@@ -26,39 +27,43 @@ void AutoRaiseApp::ArgvReceived(int32 argc, char ** argv)
{
BString option;
bool inDeskbar = false, persist = false;
BString usageNote;
usageNote = "\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open "
"window, will just put " APP_NAME " into tray\n\t--persist will put "
APP_NAME " into tray such that it remains between bootings\n";
for (int32 i = 1; i < argc; i++)
{
option = argv[i];
if (option.IFindFirst("deskbar") != B_ERROR)
inDeskbar = true;
if (option.IFindFirst("persist") != B_ERROR)
persist = true;
}
if (inDeskbar && !persist)
{
printf(APP_NAME" being put into Tray (one shot)...\n");
printf(APP_NAME " being put into Tray (one shot)...\n");
PutInTray(false);
_directToDeskbar = true;
}
else if (inDeskbar && persist)
{
printf(APP_NAME" being put into Tray (persistant)...\n");
printf(APP_NAME " being put into Tray (persistant)...\n");
PutInTray(true);
_directToDeskbar = true;
}
else
{
printf("\nUsage: "APP_NAME" [options]\n\t--deskbar\twill not open window, will just put "APP_NAME" into tray\n\t--persist will put "APP_NAME" into tray such that it remains between bootings\n");
printf(usageNote);
}
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
}
@@ -66,12 +71,16 @@ void AutoRaiseApp::ReadyToRun()
{
if (!_directToDeskbar)
{
printf("\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open window, will just put " APP_NAME " into tray\n\t--persist will put " APP_NAME " into tray such that it remains between bootings\n");
BAlert *alert = new BAlert("usage box", APP_NAME ", (c) 2002, mmu_man\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open window, will just put " APP_NAME " into tray\n\t--persist will put "APP_NAME" into tray such that it remains between bootings\n", "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
alert->SetShortcut(0, B_ENTER);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
printf(usageNote);
BAlert *alert = new BAlert("usage box", APP_NAME ", (c) 2002, "
"mmu_man\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not "
"open window, will just put " APP_NAME " into tray\n\t--persist "
"will put " APP_NAME " into tray such that it remains between "
"bootings\n", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING,
B_INFO_ALERT);
alert->SetShortcut(0, B_ENTER);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go();
be_app_messenger.SendMessage(B_QUIT_REQUESTED);
}
}
@@ -79,7 +88,7 @@ void AutoRaiseApp::ReadyToRun()
void AutoRaiseApp::PutInTray(bool persist)
{
BDeskbar db;
if (!persist)
db.AddItem(new TrayView);
else {
@@ -95,5 +104,4 @@ int main()
{
AutoRaiseApp *app = new AutoRaiseApp();
app->Run();
}
+3
View File
@@ -20,6 +20,9 @@ class AutoRaiseApp: public BApplication{
virtual void ReadyToRun();
void PutInTray(bool);
private:
BString usageNote;
};
#endif
+25 -107
View File
@@ -1,10 +1,4 @@
/* this is for the DANO hack (new, simpler version than the BStringIO hack) */
#include <BeBuild.h>
#ifdef B_BEOS_VERSION_DANO
#define private public
#include <Messenger.h>
#undef private
#endif
#include "AutoRaiseIcon.h"
#include <stdlib.h>
@@ -21,13 +15,14 @@ extern "C" _EXPORT BView *instantiate_deskbar_item(void)
}
long removeFromDeskbar(void *)
status_t removeFromDeskbar(void *)
{
BDeskbar db;
if (db.RemoveItem(APP_NAME) != B_OK)
if (db.RemoveItem(APP_NAME) != B_OK) {
printf("Unable to remove AutoRaise from BDeskbar\n");
}
return 0;
return B_OK;
}
//**************************************************
@@ -61,9 +56,6 @@ ConfigMenu::ConfigMenu(TrayView *tv, bool useMag)
msg->AddInt32(AR_MODE, Mode_DeskbarOver);
tmpi = new BMenuItem("Deskbar only (over its area)", msg);
tmpi->SetMarked(s->Mode() == Mode_DeskbarOver);
#ifdef USE_DANO_HACK
tmpi->SetEnabled(false);
#endif
tmpm->AddItem(tmpi);
msg = new BMessage(MSG_SET_MODE);
@@ -170,7 +162,7 @@ ConfigMenu::ConfigMenu(TrayView *tv, bool useMag)
AddSeparatorItem();
// AddItem(new BMenuItem("Settings...", new BMessage(OPEN_SETTINGS)));
AddItem(new BMenuItem("About "APP_NAME B_UTF8_ELLIPSIS,
AddItem(new BMenuItem("About " APP_NAME B_UTF8_ELLIPSIS,
new BMessage(B_ABOUT_REQUESTED)));
AddItem(new BMenuItem("Remove from tray", new BMessage(REMOVE_FROM_TRAY)));
@@ -221,10 +213,8 @@ void TrayView::_init()
get_thread_info(find_thread(NULL), &ti);
fDeskbarTeam = ti.team;
#ifndef USE_DANO_HACK
resume_thread(poller_thread = spawn_thread(poller, "AutoRaise desktop "
"poller", B_NORMAL_PRIORITY, (void *)this));
#endif
//determine paths to icon files based on app path in settings file
@@ -269,18 +259,11 @@ TrayView::~TrayView(){
status_t ret;
if (watching) {
#ifdef USE_DANO_HACK
be_roster->StopWatching(this);
#else
// acquire_sem(fPollerSem);
#endif
set_mouse_mode(fNormalMM);
watching = false;
}
delete_sem(fPollerSem);
#ifndef USE_DANO_HACK
wait_for_thread(poller_thread, &ret);
#endif
if (_activeIcon) delete _activeIcon;
if (_inactiveIcon) delete _inactiveIcon;
if (_settings) delete _settings;
@@ -303,8 +286,7 @@ status_t TrayView::Archive(BMessage *data, bool deep) const {
//Rehydrate the View from a given message (called by the DeskBar)
TrayView *TrayView::Instantiate(BMessage *data) {
if (!validate_instantiation(data, "TrayView"))
{
if (!validate_instantiation(data, "TrayView")) {
return NULL;
}
@@ -314,16 +296,12 @@ TrayView *TrayView::Instantiate(BMessage *data) {
void TrayView::AttachedToWindow() {
if(Parent())
SetViewColor(Parent()->ViewColor());
if (_settings->Active()) {
fNormalMM = mouse_mode();
set_mouse_mode(B_FOCUS_FOLLOWS_MOUSE);
#ifdef USE_DANO_HACK
be_roster->StartWatching(this, B_REQUEST_WINDOW_ACTIVATED);
#else
release_sem(fPollerSem);
#endif
watching = true;
}
if (_settings->Active()) {
fNormalMM = mouse_mode();
set_mouse_mode(B_FOCUS_FOLLOWS_MOUSE);
release_sem(fPollerSem);
watching = true;
}
}
void TrayView::Draw(BRect updaterect) {
@@ -389,16 +367,14 @@ void TrayView::MouseDown(BPoint where) {
int32 fronter(void *arg)
{
TrayView *tv = (TrayView *)arg;
int32 tok = tv->current_window;
int32 ws = current_workspace();
volatile int32 tok = tv->current_window;
sem_id sem = tv->fPollerSem;
snooze(tv->raise_delay);
#ifndef USE_DANO_HACK
if (acquire_sem(sem) != B_OK)
return B_OK; // this really needs a better locking model...
#endif
if (ws != current_workspace())
goto end; // don't touch windows if we changed workspace
if (tv->last_raiser_thread != find_thread(NULL))
@@ -415,7 +391,6 @@ PRINT(("tok = %ld cw = %ld\n", tok, tv->current_window));
return B_OK;
}
#ifndef USE_DANO_HACK
int32 poller(void *arg)
{
@@ -451,7 +426,8 @@ int32 poller(void *arg)
goto zzz; // invalid window ?
/*
printf("if (!%s && (%li, %li)isin(%li)(%li, %li, %li, %li) && (%li != %li) ", wi->is_mini?"true":"false",
(long)mouse.x, (long)mouse.y, i, wi->window_left, wi->window_right, wi->window_top, wi->window_bottom, wi->id, tok);
(long)mouse.x, (long)mouse.y, i, wi->window_left, wi->window_right,
wi->window_top, wi->window_bottom, wi-server_token, tok);
*/
@@ -460,12 +436,13 @@ printf("if (!%s && (%li, %li)isin(%li)(%li, %li, %li, %li) && (%li != %li) ", wi
&& (((long)mouse.y) > wi->window_top) && (((long)mouse.y) < wi->window_bottom)) {
//((tv->_settings->Mode() != Mode_DeskbarOver) || (wi->team == tv->fDeskbarTeam))
if ((tv->_settings->Mode() == Mode_All) && (wi->id == tv->current_window))
if ((tv->_settings->Mode() == Mode_All) &&
(wi->server_token == tv->current_window))
goto zzz; // already raised
if ((tv->_settings->Mode() == Mode_All) || (wi->team == tv->fDeskbarTeam)) {
tv->current_window = wi->id;
tok = wi->id;
tv->current_window = wi->server_token;
tok = wi->server_token;
resume_thread(tv->last_raiser_thread = spawn_thread(fronter, "fronter", B_NORMAL_PRIORITY, (void *)tv));
goto zzz;
} else if (tv->_settings->Mode() == Mode_DeskbarTouch) // give up, before we find Deskbar under it
@@ -487,7 +464,6 @@ printf("if (!%s && (%li, %li)isin(%li)(%li, %li, %li, %li) && (%li != %li) ", wi
return B_OK;
}
#endif
void TrayView::MessageReceived(BMessage* message)
{
@@ -533,72 +509,22 @@ void TrayView::MessageReceived(BMessage* message)
}
case REMOVE_FROM_TRAY:
{
thread_id tid = spawn_thread(removeFromDeskbar, "RemoveFromDeskbar", B_NORMAL_PRIORITY, NULL);
if (tid) resume_thread(tid);
thread_id tid = spawn_thread(removeFromDeskbar, "RemoveFromDeskbar", B_NORMAL_PRIORITY, (void*)this);
if (tid != 0) resume_thread(tid);
break;
}
case B_ABOUT_REQUESTED:
alert = new BAlert("about box", "AutoRaise, (c) 2002, mmu_man\nEnjoy :-)", "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
alert->SetShortcut(0, B_ENTER);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL); // use asynchronous version
B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_INFO_ALERT);
alert->SetShortcut(0, B_ENTER);
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
alert->Go(NULL); // use asynchronous version
break;
case OPEN_SETTINGS:
break;
#ifdef USE_DANO_HACK
case B_SOME_WINDOW_ACTIVATED:
// printf("Window Activated\n");
// message->PrintToStream();
BPoint mouse;
uint32 buttons;
GetMouse(&mouse, &buttons);
if (buttons)
break;
if (message->FindMessenger("be:window", &msgr) < B_OK)
puts("BMsgr ERROR");
else {
bool doZoom = false;
BRect zoomRect(0.0f, 0.0f, 0.0f, 0.0f);
port_id pi = msgr.fPort;
// printf("port:%li (%lx)\n", pi, pi);
int32 *tl, tlc;
tl = get_token_list(msgr.Team(), &tlc);
// printf("tokens (team %li): (%li) ", msgr.Team(), tlc);
for (tlc; tlc; tlc--) {
// printf("%li ", tl[tlc-1]);
window_info *wi = get_window_info(tl[tlc-1]);
if (wi) {
if (wi->client_port == pi) {
if ((wi->layer < 3) // we hit the desktop or a window not on this WS
|| (wi->window_left > wi->window_right) || (wi->window_top > wi->window_bottom)
|| (wi->is_mini)
|| (/*(_settings->Mode() == Mode_All) && */(wi->id == current_window))) {
// already raised
free(wi);
break;
}
if ((_settings->Mode() == Mode_All) || (wi->team == fDeskbarTeam)) {
PRINT(("raising wi=%li, cp=%ld, pi=%ld team=%ld DBteam=%ld\n", wi->id, wi->client_port, pi, wi->team, fDeskbarTeam));
current_window = wi->id;
int32 tok = wi->id;
resume_thread(last_raiser_thread = spawn_thread(fronter, "fronter", B_NORMAL_PRIORITY, (void *)this));
} else {
current_window = wi->id;
}
}
free(wi);
}
}
// puts("");
free(tl);
}
break;
#endif
default:
BView::MessageReceived(message);
}
@@ -617,22 +543,14 @@ void TrayView::SetActive(bool st)
if (!watching) {
fNormalMM = mouse_mode();
set_mouse_mode(B_FOCUS_FOLLOWS_MOUSE);
#ifdef USE_DANO_HACK
be_roster->StartWatching(this, B_REQUEST_WINDOW_ACTIVATED);
#else
release_sem(fPollerSem);
#endif
watching = true;
}
}
else
{
if (watching) {
#ifdef USE_DANO_HACK
be_roster->StopWatching(this);
#else
acquire_sem(fPollerSem);
#endif
set_mouse_mode(fNormalMM);
watching = false;
}
+16 -16
View File
@@ -16,9 +16,9 @@ extern "C" _EXPORT BView* instantiate_deskbar_item();
//since we can't remove the view from the deskbar from within the same thread
//as tray view, a thread will be spawned and this function called. It removed TrayView
//from the Deskbar
long removeFromDeskbar(void *);
//as tray view, a thread will be spawned and this function called. It removed
//TrayView from the Deskbar
status_t removeFromDeskbar(void *);
class _EXPORT TrayView;
@@ -27,20 +27,20 @@ class _EXPORT TrayView;
class TrayView derived from BView
The icon in the Deskbar tray, provides the fundamental
user interface. Archivable, so it can be flattened and fired
at the deskbar.
user interface. Archivable, so it can be flattened and
fired at the deskbar.
*********************************************/
class TrayView:public BView{
private:
BBitmap *_activeIcon, *_inactiveIcon;
entry_ref _appPath;
bool watching;
void _init(void); //initialization common to all constructors
void _init(void); //initialization common to all constructors
public:
AutoRaiseSettings *_settings;
mode_mouse fNormalMM;
@@ -48,24 +48,24 @@ class TrayView:public BView{
bigtime_t raise_delay;
volatile thread_id last_raiser_thread;
team_id fDeskbarTeam;
bigtime_t polling_delay; // for !DANO
bigtime_t polling_delay;
sem_id fPollerSem;
thread_id poller_thread;
TrayView();
TrayView(BMessage *mdArchive);
virtual ~TrayView();
virtual status_t Archive(BMessage *data, bool deep = true) const;
static TrayView *Instantiate(BMessage *data);
virtual void Draw(BRect updateRect );
virtual void AttachedToWindow();
virtual void MouseDown(BPoint where);
virtual void MessageReceived(BMessage* message);
virtual void GetPreferredSize(float *w, float *h);
AutoRaiseSettings *Settings() const;
void SetActive(bool);
};
@@ -84,7 +84,7 @@ int32 poller(void *);
class ConfigMenu: public BPopUpMenu{
private:
public:
ConfigMenu(TrayView *tv, bool useMag);
virtual ~ConfigMenu();
+3
View File
@@ -1,5 +1,8 @@
SubDir HAIKU_TOP src apps autoraise ;
UsePrivateHeaders interface shared ;
UsePrivateHeaders private shared ;
SetSubDirSupportedPlatformsBeOSCompatible ;
Application AutoRaise :
+2 -50
View File
@@ -7,12 +7,7 @@
#include <InterfaceKit.h>
#include <String.h>
#include <StorageKit.h>
// R5.1 has a very helpful API...
#if (B_BEOS_VERSION == 0x0510)
#define USE_DANO_HACK
#endif
#include <WindowInfo.h>
/***************************************************
common.h
@@ -21,7 +16,7 @@
// used to check the image to use to get the resources
#define APP_NAME "AutoRaise"
#define APP_SIG "application/x-vnd.mmu.AutoRaise"
#define APP_SIG "application/x-vnd.mmu.AutoRaise"
#define SETTINGS_FILE "x-vnd.mmu.AutoRaise_settings"
//names of data segments in settings file
@@ -51,12 +46,8 @@ enum {
#define ADD_TO_TRAY 'zATT'
#define REMOVE_FROM_TRAY 'zRFT'
#define OPEN_SETTINGS 'zOPS'
#define MSG_DELAY_POPUP 'arDP'
#define MSG_TOGGLE_ACTIVE 'arTA'
#define MSG_SET_ACTIVE 'arSA'
#define MSG_SET_INACTIVE 'arSI'
@@ -64,43 +55,4 @@ enum {
#define MSG_SET_MODE 'arSM'
#define MSG_SET_BEHAVIOUR 'arSB'
/* from OpenTracker deskbar/WindowMenuItem.h */
// from interface_defs.h
struct window_info {
team_id team;
int32 id; /* window's token */
int32 thread;
int32 client_token;
int32 client_port;
uint32 workspaces;
int32 layer;
uint32 w_type; /* B_TITLED_WINDOW, etc. */
uint32 flags; /* B_WILL_FLOAT, etc. */
int32 window_left;
int32 window_top;
int32 window_right;
int32 window_bottom;
int32 show_hide_level;
bool is_mini;
char name[1];
};
// from interface_misc.h
enum window_action {
B_MINIMIZE_WINDOW,
B_BRING_TO_FRONT
};
// from interface_misc.h
void do_window_action(int32 window_id, int32 action,
BRect zoomRect, bool zoom);
window_info *get_window_info(int32 a_token);
int32 *get_token_list(team_id app, int32 *count);
void do_minimize_team(BRect zoomRect, team_id team, bool zoom);
void do_bring_to_front_team(BRect zoomRect, team_id app, bool zoom);
#endif