added initial team monitor
fixed device naming git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9492 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
1a3a7e8cd8
commit
ca4719945c
|
@ -5,6 +5,10 @@ UsePrivateHeaders input ;
|
|||
Addon <input>keyboard : input_server/devices :
|
||||
KeyboardInputDevice.cpp
|
||||
Keymap.cpp
|
||||
|
||||
TMWindow.cpp
|
||||
TMListItem.cpp
|
||||
|
||||
: false
|
||||
: be <nogrist>input_server ;
|
||||
|
||||
|
|
|
@ -35,18 +35,9 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#if DEBUG
|
||||
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
|
||||
fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); }
|
||||
#define LOG_ERR(text...) LOG(text)
|
||||
|
||||
FILE *KeyboardInputDevice::sLogFile = NULL;
|
||||
#else
|
||||
#define LOG(text...)
|
||||
#define LOG_ERR(text...) fprintf(stderr, text)
|
||||
#endif
|
||||
|
||||
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
||||
|
||||
const static uint32 kSetLeds = 0x2711;
|
||||
const static uint32 kSetRepeatingKey = 0x2712;
|
||||
const static uint32 kSetNonRepeatingKey = 0x2713;
|
||||
|
@ -365,6 +356,7 @@ instantiate_input_device()
|
|||
|
||||
|
||||
KeyboardInputDevice::KeyboardInputDevice()
|
||||
: fTMWindow(NULL)
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
|
@ -388,6 +380,17 @@ KeyboardInputDevice::~KeyboardInputDevice()
|
|||
}
|
||||
|
||||
|
||||
status_t
|
||||
KeyboardInputDevice::SystemShuttingDown()
|
||||
{
|
||||
CALLED();
|
||||
if (fTMWindow) {
|
||||
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
KeyboardInputDevice::InitFromSettings(void *cookie, uint32 opcode)
|
||||
{
|
||||
|
@ -478,6 +481,9 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
|
|||
wait_for_thread(device->device_watcher, &dummy);
|
||||
}
|
||||
|
||||
if (fTMWindow)
|
||||
fTMWindow->PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
@ -666,8 +672,14 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
|
|||
&& (states[0x5c >> 3] & (1 << (7 - (0x5c & 0x7))))
|
||||
&& (states[0x5d >> 3] & (1 << (7 - (0x5d & 0x7))))) {
|
||||
|
||||
LOG("TeamMonitor called\n");
|
||||
|
||||
// show the team monitor
|
||||
// argh we don't have one !
|
||||
if (!dev->owner->fTMWindow)
|
||||
dev->owner->fTMWindow = new TMWindow();
|
||||
|
||||
dev->owner->fTMWindow->Enable();
|
||||
|
||||
// cancel timer only for R5
|
||||
if (ioctl(dev->fd, kCancelTimer, NULL) == B_OK)
|
||||
|
@ -776,12 +788,12 @@ KeyboardInputDevice::GetShortName(const char *longName)
|
|||
BString name;
|
||||
|
||||
int32 slash = string.FindLast("/");
|
||||
int32 previousSlash = string.FindLast("/", slash) + 1;
|
||||
string.CopyInto(name, slash, string.Length() - slash);
|
||||
string.CopyInto(name, slash + 1, string.Length() - slash);
|
||||
int32 index = atoi(name.String()) + 1;
|
||||
|
||||
int32 deviceIndex = atoi(name.String()) + 1;
|
||||
string.CopyInto(name, previousSlash, slash - previousSlash);
|
||||
name << " Keyboard " << deviceIndex;
|
||||
int32 previousSlash = string.FindLast("/", slash);
|
||||
string.CopyInto(name, previousSlash + 1, slash - previousSlash - 1);
|
||||
name << " Keyboard " << index;
|
||||
|
||||
return strdup(name.String());
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define __KEYBOARDINPUTDEVICE_H
|
||||
|
||||
#include "Keymap.h"
|
||||
#include "TMWindow.h"
|
||||
#include <InputServerDevice.h>
|
||||
#include <List.h>
|
||||
#include <stdio.h>
|
||||
|
@ -60,6 +61,8 @@ public:
|
|||
|
||||
virtual status_t Control(const char *name, void *cookie,
|
||||
uint32 command, BMessage *message);
|
||||
|
||||
virtual status_t SystemShuttingDown();
|
||||
#ifdef DEBUG
|
||||
static FILE *sLogFile;
|
||||
#endif
|
||||
|
@ -78,9 +81,21 @@ private:
|
|||
|
||||
BList fDevices;
|
||||
Keymap fKeymap;
|
||||
TMWindow *fTMWindow;
|
||||
};
|
||||
|
||||
extern "C" BInputServerDevice *instantiate_input_device();
|
||||
|
||||
#if DEBUG
|
||||
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
|
||||
fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); }
|
||||
#define LOG_ERR(text...) LOG(text)
|
||||
#else
|
||||
#define LOG(text...)
|
||||
#define LOG_ERR(text...) fprintf(stderr, text)
|
||||
#endif
|
||||
|
||||
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -368,4 +368,4 @@ Keymap::LoadCurrent()
|
|||
memcpy(&fKeys, keys, sizeof(fKeys));
|
||||
delete keys;
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2004, Haiku
|
||||
//
|
||||
// This software is part of the Haiku distribution and is covered
|
||||
// by the Haiku license.
|
||||
//
|
||||
//
|
||||
// File: TMListItem.cpp
|
||||
// Author: Jérôme Duval
|
||||
// Description: Keyboard input server addon
|
||||
// Created : October 24, 2004
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#include <string.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <View.h>
|
||||
#include "TMListItem.h"
|
||||
|
||||
#define kITEM_MARGIN 1
|
||||
|
||||
|
||||
TMListItem::TMListItem(team_info &tinfo)
|
||||
: BListItem(),
|
||||
fInfo(tinfo),
|
||||
fIcon(BRect(0,0,15,15), B_CMAP8)
|
||||
{
|
||||
SetHeight(16 + kITEM_MARGIN);
|
||||
|
||||
int32 cookie = 0;
|
||||
image_info info;
|
||||
if (get_next_image_info(tinfo.team, &cookie, &info) == B_OK) {
|
||||
fPath = BPath(info.name);
|
||||
BNode node(info.name);
|
||||
BNodeInfo nodeInfo(&node);
|
||||
nodeInfo.GetTrackerIcon(&fIcon, B_MINI_ICON);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TMListItem::~TMListItem()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMListItem::DrawItem(BView *owner, BRect frame, bool complete)
|
||||
{
|
||||
rgb_color kHighlight = { 140,140,140,0 };
|
||||
rgb_color kBlack = { 0,0,0,0 };
|
||||
rgb_color kBlue = { 0,0,255,0 };
|
||||
|
||||
BRect r(frame);
|
||||
|
||||
if (IsSelected() || complete) {
|
||||
rgb_color color;
|
||||
if (IsSelected()) {
|
||||
color = kHighlight;
|
||||
} else {
|
||||
color = owner->ViewColor();
|
||||
}
|
||||
owner->SetHighColor(color);
|
||||
owner->SetLowColor(color);
|
||||
owner->FillRect(r);
|
||||
owner->SetHighColor(kBlack);
|
||||
} else {
|
||||
owner->SetLowColor(owner->ViewColor());
|
||||
}
|
||||
|
||||
frame.left += 4;
|
||||
BRect iconFrame(frame);
|
||||
iconFrame.Set(iconFrame.left, iconFrame.top+1, iconFrame.left+15, iconFrame.top+16);
|
||||
owner->SetDrawingMode(B_OP_OVER);
|
||||
owner->DrawBitmap(&fIcon, iconFrame);
|
||||
owner->SetDrawingMode(B_OP_COPY);
|
||||
|
||||
frame.left += 16;
|
||||
owner->SetHighColor(IsSystemServer() ? kBlue : kBlack);
|
||||
|
||||
BFont font = be_plain_font;
|
||||
font_height finfo;
|
||||
font.GetHeight(&finfo);
|
||||
owner->SetFont(&font);
|
||||
owner->MovePenTo(frame.left+8, frame.top + ((frame.Height() - (finfo.ascent + finfo.descent + finfo.leading)) / 2) +
|
||||
(finfo.ascent + finfo.descent) - 1);
|
||||
owner->DrawString(fPath.Leaf());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMListItem::Update(BView *owner, const BFont *finfo)
|
||||
{
|
||||
// we need to override the update method so we can make sure are
|
||||
// list item size doesn't change
|
||||
BListItem::Update(owner, finfo);
|
||||
if ((Height() < 16 + kITEM_MARGIN)) {
|
||||
SetHeight(16 + kITEM_MARGIN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const team_info *
|
||||
TMListItem::GetInfo()
|
||||
{
|
||||
return &fInfo;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TMListItem::IsSystemServer()
|
||||
{
|
||||
char system1[] = "/boot/beos/system/";
|
||||
char system2[] = "/system/servers/";
|
||||
if (strncmp(system1, fInfo.args, strlen(system1))==0)
|
||||
return true;
|
||||
if (strncmp(system2, fInfo.args, strlen(system2))==0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2004, Haiku
|
||||
//
|
||||
// This software is part of the Haiku distribution and is covered
|
||||
// by the Haiku license.
|
||||
//
|
||||
//
|
||||
// File: TMListItem.h
|
||||
// Author: Jérôme Duval
|
||||
// Description: Keyboard input server addon
|
||||
// Created : October 24, 2004
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#ifndef TMLISTITEM_H
|
||||
#define TMLISTITEM_H
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <ListItem.h>
|
||||
#include <Path.h>
|
||||
|
||||
class TMListItem : public BListItem
|
||||
{
|
||||
public:
|
||||
TMListItem(team_info &info);
|
||||
~TMListItem();
|
||||
|
||||
virtual void DrawItem(BView *owner, BRect frame, bool complete = false);
|
||||
virtual void Update(BView *owner, const BFont *finfo);
|
||||
const team_info *GetInfo();
|
||||
|
||||
bool fFound;
|
||||
private:
|
||||
bool IsSystemServer();
|
||||
team_info fInfo;
|
||||
BBitmap fIcon;
|
||||
BPath fPath;
|
||||
};
|
||||
|
||||
|
||||
#endif //TMLISTITEM_H
|
|
@ -0,0 +1,203 @@
|
|||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2004, Haiku
|
||||
//
|
||||
// This software is part of the Haiku distribution and is covered
|
||||
// by the Haiku license.
|
||||
//
|
||||
//
|
||||
// File: TMWindow.cpp
|
||||
// Author: Jérôme Duval
|
||||
// Description: Keyboard input server addon
|
||||
// Created : October 13, 2004
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#include "TMWindow.h"
|
||||
#include "TMListItem.h"
|
||||
#include "KeyboardInputDevice.h"
|
||||
#include <Message.h>
|
||||
#include <ScrollView.h>
|
||||
#include <Screen.h>
|
||||
|
||||
const uint32 TM_CANCEL = 'TMca';
|
||||
const uint32 TM_FORCE_REBOOT = 'TMfr';
|
||||
const uint32 TM_KILL_APPLICATION = 'TMka';
|
||||
const uint32 TM_SELECTED_TEAM = 'TMst';
|
||||
|
||||
TMWindow::TMWindow()
|
||||
: BWindow(BRect(0,0,350,300), "Team Monitor",
|
||||
B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL,
|
||||
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE| B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS),
|
||||
fQuitting(false)
|
||||
{
|
||||
Lock();
|
||||
|
||||
BRect rect = Bounds();
|
||||
|
||||
fBackground = new TMBox(rect, "background", B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
B_WILL_DRAW, B_NO_BORDER);
|
||||
AddChild(fBackground);
|
||||
|
||||
rect = Bounds();
|
||||
rect.right -= 10;
|
||||
rect.left = rect.right - 75;
|
||||
rect.bottom -= 14;
|
||||
rect.top = rect.bottom - 20;
|
||||
|
||||
BButton *cancel = new BButton(rect, "cancel", "Cancel",
|
||||
new BMessage(TM_CANCEL), B_FOLLOW_RIGHT|B_FOLLOW_BOTTOM);
|
||||
fBackground->AddChild(cancel);
|
||||
SetDefaultButton(cancel);
|
||||
|
||||
rect.left = 10;
|
||||
rect.right = rect.left + 83;
|
||||
|
||||
BButton *forceReboot = new BButton(rect, "force", "Force Reboot",
|
||||
new BMessage(TM_FORCE_REBOOT), B_FOLLOW_LEFT|B_FOLLOW_BOTTOM);
|
||||
fBackground->AddChild(forceReboot);
|
||||
|
||||
rect.top -= 97;
|
||||
rect.bottom = rect.top + 20;
|
||||
rect.right += 1;
|
||||
|
||||
fKillApp = new BButton(rect, "kill", "Kill Application",
|
||||
new BMessage(TM_KILL_APPLICATION), B_FOLLOW_LEFT|B_FOLLOW_BOTTOM);
|
||||
fBackground->AddChild(fKillApp);
|
||||
fKillApp->SetEnabled(false);
|
||||
|
||||
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
|
||||
BPoint pt;
|
||||
pt.x = screenFrame.Width()/2 - Bounds().Width()/2;
|
||||
pt.y = screenFrame.Height()/2 - Bounds().Height()/2;
|
||||
|
||||
if (screenFrame.Contains(pt))
|
||||
MoveTo(pt);
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
TMWindow::~TMWindow()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what)
|
||||
{
|
||||
case TM_KILL_APPLICATION: {
|
||||
TMListItem *item = (TMListItem*)fBackground->fListView->ItemAt(
|
||||
fBackground->fListView->CurrentSelection());
|
||||
kill_team(item->GetInfo()->team);
|
||||
fKillApp->SetEnabled(false);
|
||||
}
|
||||
break;
|
||||
case TM_SELECTED_TEAM:
|
||||
fKillApp->SetEnabled(true);
|
||||
break;
|
||||
case TM_CANCEL:
|
||||
Disable();
|
||||
break;
|
||||
case SYSTEM_SHUTTING_DOWN:
|
||||
fQuitting = true;
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
TMWindow::QuitRequested()
|
||||
{
|
||||
Disable();
|
||||
return fQuitting;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMWindow::Enable()
|
||||
{
|
||||
SetPulseRate(1000000);
|
||||
|
||||
if (IsHidden())
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMWindow::Disable()
|
||||
{
|
||||
SetPulseRate(0);
|
||||
Hide();
|
||||
}
|
||||
|
||||
|
||||
TMBox::TMBox(BRect bounds, const char* name, uint32 resizeFlags,
|
||||
uint32 flags, border_style border)
|
||||
: BBox(bounds, name, resizeFlags, flags | B_PULSE_NEEDED, border)
|
||||
{
|
||||
|
||||
BRect rect = Bounds();
|
||||
rect.InsetBy(12, 11);
|
||||
rect.right -= B_V_SCROLL_BAR_WIDTH;
|
||||
rect.bottom = rect.top + 146;
|
||||
|
||||
fListView = new BListView(rect, "teams", B_SINGLE_SELECTION_LIST,
|
||||
B_FOLLOW_ALL);
|
||||
fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM));
|
||||
|
||||
BScrollView *sv = new BScrollView("scroll_teams", fListView,
|
||||
B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER);
|
||||
|
||||
AddChild(sv);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TMBox::Pulse()
|
||||
{
|
||||
CALLED();
|
||||
int32 cookie = 0;
|
||||
team_info info;
|
||||
|
||||
for (int32 i=0; i<fListView->CountItems(); i++) {
|
||||
TMListItem *item = (TMListItem*)fListView->ItemAt(i);
|
||||
item->fFound = false;
|
||||
}
|
||||
|
||||
while (get_next_team_info(&cookie, &info) == B_OK) {
|
||||
if (info.team <=16)
|
||||
continue;
|
||||
|
||||
bool found = false;
|
||||
for (int32 i=0; i<fListView->CountItems(); i++) {
|
||||
TMListItem *item = (TMListItem*)fListView->ItemAt(i);
|
||||
if (item->GetInfo()->team == info.team) {
|
||||
item->fFound = true;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
TMListItem *item = new TMListItem(info);
|
||||
fListView->AddItem(item, 0);
|
||||
item->fFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32 i=fListView->CountItems()-1; i>=0; i--) {
|
||||
TMListItem *item = (TMListItem*)fListView->ItemAt(i);
|
||||
if (!item->fFound)
|
||||
delete fListView->RemoveItem(i);
|
||||
}
|
||||
|
||||
fListView->Invalidate();
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
//
|
||||
// Copyright (c) 2004, Haiku
|
||||
//
|
||||
// This software is part of the Haiku distribution and is covered
|
||||
// by the Haiku license.
|
||||
//
|
||||
//
|
||||
// File: TMWindow.h
|
||||
// Author: Jérôme Duval
|
||||
// Description: Keyboard input server addon
|
||||
// Created : October 13, 2004
|
||||
//
|
||||
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
||||
|
||||
#ifndef TMWINDOW_H
|
||||
#define TMWINDOW_H
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <ListView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "InputServerTypes.h"
|
||||
|
||||
class TMBox : public BBox {
|
||||
public:
|
||||
TMBox(BRect bounds, const char* name=NULL, uint32 resizeFlags = B_FOLLOW_LEFT|B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW|B_FRAME_EVENTS|B_NAVIGABLE_JUMP,
|
||||
border_style border = B_FANCY_BORDER);
|
||||
void Pulse();
|
||||
|
||||
BListView *fListView;
|
||||
};
|
||||
|
||||
class TMWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
TMWindow();
|
||||
~TMWindow();
|
||||
|
||||
void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested();
|
||||
void Enable();
|
||||
void Disable();
|
||||
private:
|
||||
bool fQuitting;
|
||||
|
||||
BButton *fKillApp;
|
||||
TMBox *fBackground;
|
||||
};
|
||||
|
||||
|
||||
#endif //TMWINDOW_H
|
Loading…
Reference in New Issue