xref: /haiku/src/apps/switcher/Switcher.cpp (revision 25a7b01d15612846f332751841da3579db313082)
1 /*
2  * Copyright 2011, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "Switcher.h"
8 
9 #include <stdlib.h>
10 
11 #include <Application.h>
12 #include <Catalog.h>
13 
14 #include "CaptureWindow.h"
15 #include "PanelWindow.h"
16 
17 
18 #undef B_TRANSLATION_CONTEXT
19 #define B_TRANSLATION_CONTEXT "Switcher"
20 
21 
22 const char* kSignature = "application/x-vnd.Haiku-Switcher";
23 
24 
Switcher()25 Switcher::Switcher()
26 	:
27 	BApplication(kSignature),
28 	fOccupiedLocations(0)
29 {
30 }
31 
32 
~Switcher()33 Switcher::~Switcher()
34 {
35 }
36 
37 
38 void
ReadyToRun()39 Switcher::ReadyToRun()
40 {
41 	CaptureWindow* window = new CaptureWindow();
42 	window->Run();
43 
44 	fCaptureMessenger = window;
45 }
46 
47 
48 void
MessageReceived(BMessage * message)49 Switcher::MessageReceived(BMessage* message)
50 {
51 	switch (message->what) {
52 		case kMsgLocationTrigger:
53 		{
54 			uint32 location = (uint32)message->FindInt32("location");
55 			if ((location & fOccupiedLocations) == 0) {
56 				// TODO: make function configurable
57 				uint32 which = kShowApplicationWindows;
58 				if ((location & (kTopEdge | kBottomEdge)) != 0)
59 					which = kShowApplications;
60 
61 				new PanelWindow(location, which,
62 					(team_id)message->FindInt32("team"));
63 				fOccupiedLocations |= location;
64 			}
65 			break;
66 		}
67 
68 		case kMsgLocationFree:
69 		{
70 			uint32 location;
71 			if (message->FindInt32("location", (int32*)&location) == B_OK)
72 				fOccupiedLocations &= ~location;
73 			break;
74 		}
75 
76 		case kMsgHideWhenMouseMovedOut:
77 			fCaptureMessenger.SendMessage(message);
78 			break;
79 
80 		default:
81 			BApplication::MessageReceived(message);
82 			break;
83 	}
84 }
85 
86 
87 //	#pragma mark -
88 
89 
90 int
main(int,char **)91 main(int /*argc*/, char** /*argv*/)
92 {
93 	Switcher app;
94 	app.Run();
95 
96 	return 0;
97 }
98