Add input server filters

... for switching workspaces (removed from BWindow) and
minimize all (aka Show Desktop).

This moves the workspace switch behavior out of the BWindow class
and places it into it's own input server filter that does the same
thing. The difference is that you may now uninstall the workspace
switching filter to disable the behavior. These shortcuts were not
included in the BeOS R5 version of BWindow so represent additional
behavior added to Haiku.

minimize_all (aka Show Desktop) is a new input server filter that
allows you to minimize all windows by pressing cmd+ctrl+D. If
you do not like this behavior you may uninstall the minimize_all
input server filter.
This commit is contained in:
John Scipione
2015-01-26 18:25:27 -05:00
parent ccc6666156
commit a0c8352718
9 changed files with 286 additions and 2 deletions
+1 -1
View File
@@ -230,7 +230,7 @@ AddSymlinkToPackage add-ons Tracker
AddFilesToPackage add-ons input_server devices
: <input>keyboard <input>mouse <input>tablet <input>wacom ;
AddFilesToPackage add-ons input_server filters
: screen_saver shortcut_catcher ;
: minimize_all screen_saver shortcut_catcher switch_workspace ;
AddFilesToPackage add-ons kernel network : <net>notifications stack ;
AddFilesToPackage add-ons kernel network : dns_resolver ;
+1 -1
View File
@@ -198,7 +198,7 @@ AddSymlinkToPackage add-ons Tracker
AddFilesToPackage add-ons input_server devices
: <input>keyboard <input>mouse <input>tablet <input>wacom ;
AddFilesToPackage add-ons input_server filters
: screen_saver shortcut_catcher ;
: minimize_all screen_saver shortcut_catcher switch_workspace ;
AddFilesToPackage add-ons kernel network : <net>notifications stack ;
AddFilesToPackage add-ons kernel network : dns_resolver ;
+2
View File
@@ -1,4 +1,6 @@
SubDir HAIKU_TOP src add-ons input_server filters ;
SubInclude HAIKU_TOP src add-ons input_server filters minimize_all ;
SubInclude HAIKU_TOP src add-ons input_server filters screen_saver ;
SubInclude HAIKU_TOP src add-ons input_server filters shortcut_catcher ;
SubInclude HAIKU_TOP src add-ons input_server filters switch_workspace ;
@@ -0,0 +1,10 @@
SubDir HAIKU_TOP src add-ons input_server filters minimize_all ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders interface tracker ;
Addon minimize_all
: MinimizeAllInputFilter.cpp
: be input_server $(TARGET_LIBSUPC++)
;
@@ -0,0 +1,93 @@
/*
* Copyright 2014 Haiku, Inc. All rights reserved
* Distributed under the terms of the MIT License.
*
* Authors:
* John Scipione, [email protected]
*/
#include "MinimizeAllInputFilter.h"
#include <string.h>
#include <InterfaceDefs.h>
#include <Message.h>
#include <OS.h>
#include <Roster.h>
#include <WindowInfo.h>
#include <tracker_private.h>
#define _MINIMIZE_ALL_ '_WMA'
extern "C" BInputServerFilter* instantiate_input_filter() {
return new MinimizeAllInputFilter();
}
MinimizeAllInputFilter::MinimizeAllInputFilter()
{
}
filter_result
MinimizeAllInputFilter::Filter(BMessage* message, BList* _list)
{
switch (message->what) {
case B_KEY_DOWN:
{
const char* bytes;
if (message->FindString("bytes", &bytes) != B_OK)
break;
int32 modifiers;
if (message->FindInt32("modifiers", &modifiers) != B_OK)
break;
int32 modifiersHeld = modifiers & (B_COMMAND_KEY
| B_CONTROL_KEY | B_OPTION_KEY | B_MENU_KEY | B_SHIFT_KEY);
bool minimize;
if (modifiersHeld == (B_COMMAND_KEY | B_CONTROL_KEY))
minimize = true;
else if (modifiersHeld
== (B_COMMAND_KEY | B_CONTROL_KEY | B_SHIFT_KEY)) {
minimize = false;
} else
break;
int32 cookie = 0;
team_info teamInfo;
while (get_next_team_info(&cookie, &teamInfo) == B_OK) {
app_info appInfo;
be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
team_id team = appInfo.team;
be_roster->ActivateApp(team);
if (be_roster->GetActiveAppInfo(&appInfo) == B_OK
&& (appInfo.flags & B_BACKGROUND_APP) == 0
&& strcasecmp(appInfo.signature, kDeskbarSignature) != 0) {
BRect zoomRect;
if (minimize)
do_minimize_team(zoomRect, team, false);
else
do_bring_to_front_team(zoomRect, team, false);
}
}
return B_SKIP_MESSAGE;
}
}
return B_DISPATCH_MESSAGE;
}
status_t
MinimizeAllInputFilter::InitCheck()
{
return B_OK;
}
@@ -0,0 +1,24 @@
/*
* Copyright 2014 Haiku, Inc. All rights reserved
* Distributed under the terms of the MIT License.
*/
#ifndef _MINIMIZE_ALL_INPUT_FILTER_H
#define _MINIMIZE_ALL_INPUT_FILTER_H
#include <InputServerFilter.h>
extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
class MinimizeAllInputFilter : public BInputServerFilter {
public:
MinimizeAllInputFilter();
virtual filter_result Filter(BMessage* message, BList* _list);
virtual status_t InitCheck();
};
#endif // _MINIMIZE_ALL_INPUT_FILTER_H
@@ -0,0 +1,10 @@
SubDir HAIKU_TOP src add-ons input_server filters switch_workspace ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders app ;
Addon switch_workspace
: SwitchWorkspaceInputFilter.cpp
: be input_server $(TARGET_LIBSUPC++)
;
@@ -0,0 +1,121 @@
/*
* Copyright 2009-2014 Haiku, Inc. All rights reserved
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, [email protected]
* John Scipione, [email protected]
*/
#include "SwitchWorkspaceInputFilter.h"
#include <string.h>
#include <AppServerLink.h>
#include <InterfaceDefs.h>
#include <Message.h>
#include <ServerProtocol.h>
#define _SWITCH_WORKSPACE_ '_SWS'
extern "C" BInputServerFilter* instantiate_input_filter() {
return new SwitchWorkspaceInputFilter();
}
SwitchWorkspaceInputFilter::SwitchWorkspaceInputFilter()
{
}
filter_result
SwitchWorkspaceInputFilter::Filter(BMessage* message, BList* _list)
{
switch (message->what) {
case B_KEY_DOWN:
{
const char* bytes;
if (message->FindString("bytes", &bytes) != B_OK)
break;
int32 modifiers;
if (message->FindInt32("modifiers", &modifiers) != B_OK)
break;
int32 modifiersHeld = modifiers & (B_COMMAND_KEY
| B_CONTROL_KEY | B_OPTION_KEY | B_MENU_KEY | B_SHIFT_KEY);
bool takeMeThere;
if (modifiersHeld == (B_COMMAND_KEY | B_CONTROL_KEY))
takeMeThere = false;
else if (modifiersHeld
== (B_COMMAND_KEY | B_CONTROL_KEY | B_SHIFT_KEY)) {
takeMeThere = true;
} else
break;
int32 deltaX = 0;
int32 deltaY = 0;
if (bytes[0] == B_LEFT_ARROW)
deltaX = -1;
else if (bytes[0] == B_UP_ARROW)
deltaY = -1;
else if (bytes[0] == B_RIGHT_ARROW)
deltaX = 1;
else if (bytes[0] == B_DOWN_ARROW)
deltaY = 1;
else
break;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_WORKSPACE_LAYOUT);
status_t status;
int32 columns;
int32 rows;
if (link.FlushWithReply(status) != B_OK || status != B_OK)
break;
link.Read<int32>(&columns);
link.Read<int32>(&rows);
int32 current = current_workspace();
int32 nextColumn = current % columns + deltaX;
if (nextColumn >= columns)
nextColumn = columns - 1;
else if (nextColumn < 0)
nextColumn = 0;
int32 nextRow = current / columns + deltaY;
if (nextRow >= rows)
nextRow = rows - 1;
else if (nextRow < 0)
nextRow = 0;
int32 next = nextColumn + nextRow * columns;
if (next != current) {
BPrivate::AppServerLink link;
link.StartMessage(AS_ACTIVATE_WORKSPACE);
link.Attach<int32>(next);
link.Attach<bool>(takeMeThere);
link.Flush();
}
return B_SKIP_MESSAGE;
}
}
return B_DISPATCH_MESSAGE;
}
status_t
SwitchWorkspaceInputFilter::InitCheck()
{
return B_OK;
}
@@ -0,0 +1,24 @@
/*
* Copyright 2014 Haiku, Inc. All rights reserved
* Distributed under the terms of the MIT License.
*/
#ifndef _SWITCH_WORKSPACE_INPUT_FILTER_H
#define _SWITCH_WORKSPACE_INPUT_FILTER_H
#include <InputServerFilter.h>
extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
class SwitchWorkspaceInputFilter : public BInputServerFilter {
public:
SwitchWorkspaceInputFilter();
virtual filter_result Filter(BMessage* message, BList* _list);
virtual status_t InitCheck();
};
#endif // _SWITCH_WORKSPACE_INPUT_FILTER_H