Skip to content

Commit be1e93c

Browse files
committed
Toggle on/off when clicking the Deskbar replicant
1 parent 8d7724e commit be1e93c

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/KeyCursor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void ShowAbout();
6969
// message codes to control the filter/device
7070
#define QUIT_COMMAND 'quIT'
7171
#define STATE 'stat'
72+
#define TOGGLE 'togl'
7273

7374
// messages of the replicant
7475
#define ABOUT 'abut'
@@ -89,6 +90,7 @@ class KeyCursorFilter : public BInputServerFilter
8990
void _AddToDeskbar();
9091
void _RemoveFromDeskbar();
9192
void _SendStatus();
93+
void _Toggle();
9294

9395
BMessenger* _ReplicantMessenger();
9496
int32 _GetReplicantAt(BMessenger target, int32 index) const;

src/KeyCursorFilter.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,9 @@ KeyCursorFilter::Filter(BMessage* message, BList* /*outList*/)
153153
// releasing the toggle modifier must have been what caused this
154154
// event. This code makes the assumption (probably incorrect) that
155155
// the only unmapped key events are generated by modifiers.
156-
if (toggleModPressedLast) {
157-
fToggleOn = !fToggleOn;
158-
beep();
156+
if (toggleModPressedLast)
157+
_Toggle();
159158

160-
_SendStatus();
161-
}
162159
toggleModPressedLast = false;
163160
}
164161
} break;
@@ -373,6 +370,8 @@ KeyCursorFilter::PrefsThreadFunc(void* cookie)
373370
}
374371
} else if (msg_code == STATE)
375372
filter->_SendStatus();
373+
else if (msg_code == TOGGLE)
374+
filter->_Toggle();
376375
}
377376

378377
return B_OK;
@@ -427,6 +426,16 @@ KeyCursorFilter::_SendStatus()
427426
}
428427

429428

429+
void
430+
KeyCursorFilter::_Toggle()
431+
{
432+
fToggleOn = !fToggleOn;
433+
beep();
434+
435+
_SendStatus();
436+
}
437+
438+
430439
BMessenger*
431440
KeyCursorFilter::_ReplicantMessenger()
432441
{

src/ReplicantView.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ ReplicantView::MouseDown(BPoint point)
132132
ConvertToScreen(&point);
133133
fPopup->Go(point, true, true, BRect(point, point + BPoint(20, 20)), true);
134134
}
135+
136+
if (buttons & B_PRIMARY_MOUSE_BUTTON)
137+
_SendMessageToFilter(TOGGLE);
135138
}
136139

137140

@@ -198,3 +201,15 @@ ReplicantView::_Init()
198201
delete icon;
199202
}
200203
}
204+
205+
206+
void
207+
ReplicantView::_SendMessageToFilter(int32 code)
208+
{
209+
port_id port = find_port(KEY_CURSOR_PREFS_PORT_NAME);
210+
211+
if (port < 0)
212+
return;
213+
214+
write_port(port, code, NULL, 0);
215+
}

src/ReplicantView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ReplicantView : public BView
3232

3333
private:
3434
void _Init();
35-
void _Remove();
35+
void _SendMessageToFilter(int32 code);
3636

3737
bool fState;
3838
BBitmap* fIconOff;

0 commit comments

Comments
 (0)