-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifyApp.cpp
More file actions
102 lines (83 loc) · 1.81 KB
/
Copy pathNotifyApp.cpp
File metadata and controls
102 lines (83 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: BSD-3-Clause
// SPDX-FileCopyrightText: 2023 Chris Roberts
#include "WatcherWindow.h"
#include <Alert.h>
#include <Application.h>
#include <iostream>
class NotifyApp : public BApplication {
public:
NotifyApp()
:
BApplication("application/x-vnd.cpr.WorkspaceNotify"),
fAutoRun(false)
{}
virtual void
MessageReceived(BMessage* message)
{
#ifdef DEBUG
std::cout << "NotifyApp::MessageReceived()" << std::endl;
message->PrintToStream();
#endif
switch (message->what) {
case B_SILENT_RELAUNCH:
{
BWindow* window = WindowAt(0);
if (window != NULL) {
window->Lock();
window->CenterOnScreen();
window->Show();
window->Unlock();
}
break;
}
default:
BApplication::MessageReceived(message);
}
}
virtual void
ReadyToRun()
{
BRect frame;
if (fAutoRun)
frame.Set(-1000, -1000, -500, -500);
else
frame.Set(200, 200, 450, 450);
WatcherWindow* window = new WatcherWindow(frame);
window->Lock();
if (!fAutoRun)
window->CenterOnScreen();
window->Show();
if (fAutoRun)
window->Hide();
window->Unlock();
}
virtual void
ArgvReceived(int32 argc, char** argv)
{
if (argc > 2) {
std::cerr << "Error: Too many arguments" << std::endl;
std::cout << "To run in background: " << argv[0] << " -r" << std::endl;
exit(1);
} else if (strcmp(argv[1], "-r") == 0)
fAutoRun = true;
else {
std::cerr << "Error: Argument not understood" << std::endl;
std::cout << "To run in background: " << argv[0] << " -r" << std::endl;
exit(1);
}
}
virtual void
AboutRequested()
{
(new BAlert("AboutWindow", "WorkspaceNotify\nWritten by Chris Roberts", "OK", NULL, NULL, B_WIDTH_FROM_LABEL))->Go();
}
private:
bool fAutoRun;
};
int
main(int /*argc*/, char** /*argv*/)
{
NotifyApp app;
app.Run();
return 0;
}