-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
InterfaceDefs.cpp
1548 lines (1186 loc) · 30.2 KB
/
InterfaceDefs.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2010, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <bpmagic@columbus.rr.com>
* Caz <turok2@currantbun.com>
* Axel Dörfler, axeld@pinc-software.de
* Michael Lotz <mmlr@mlotz.ch>
* Wim van der Meer <WPJvanderMeer@gmail.com>
*/
/*! Global functions and variables for the Interface Kit */
#include <InterfaceDefs.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Bitmap.h>
#include <Clipboard.h>
#include <ControlLook.h>
#include <Font.h>
#include <Menu.h>
#include <Point.h>
#include <Roster.h>
#include <Screen.h>
#include <ScrollBar.h>
#include <String.h>
#include <TextView.h>
#include <Window.h>
#include <ApplicationPrivate.h>
#include <AppServerLink.h>
#include <ColorConversion.h>
#include <DecorInfo.h>
#include <DefaultColors.h>
#include <InputServerTypes.h>
#include <input_globals.h>
#include <InterfacePrivate.h>
#include <MenuPrivate.h>
#include <pr_server.h>
#include <ServerProtocol.h>
#include <ServerReadOnlyMemory.h>
#include <truncate_string.h>
#include <utf8_functions.h>
#include <WidthBuffer.h>
#include <WindowInfo.h>
using namespace BPrivate;
// some other weird struct exported by BeOS, it's not initialized, though
struct general_ui_info {
rgb_color background_color;
rgb_color mark_color;
rgb_color highlight_color;
bool color_frame;
rgb_color window_frame_color;
};
struct general_ui_info general_info;
menu_info *_menu_info_ptr_;
extern "C" const char B_NOTIFICATION_SENDER[] = "be:sender";
static const rgb_color _kDefaultColors[kColorWhichCount] = {
{216, 216, 216, 255}, // B_PANEL_BACKGROUND_COLOR
{216, 216, 216, 255}, // B_MENU_BACKGROUND_COLOR
{255, 203, 0, 255}, // B_WINDOW_TAB_COLOR
{0, 0, 229, 255}, // B_KEYBOARD_NAVIGATION_COLOR
{51, 102, 152, 255}, // B_DESKTOP_COLOR
{153, 153, 153, 255}, // B_MENU_SELECTED_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_MENU_ITEM_TEXT_COLOR
{0, 0, 0, 255}, // B_MENU_SELECTED_ITEM_TEXT_COLOR
{0, 0, 0, 255}, // B_MENU_SELECTED_BORDER_COLOR
{0, 0, 0, 255}, // B_PANEL_TEXT_COLOR
{255, 255, 255, 255}, // B_DOCUMENT_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_DOCUMENT_TEXT_COLOR
{245, 245, 245, 255}, // B_CONTROL_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_CONTROL_TEXT_COLOR
{0, 0, 0, 255}, // B_CONTROL_BORDER_COLOR
{102, 152, 203, 255}, // B_CONTROL_HIGHLIGHT_COLOR
{0, 0, 0, 255}, // B_NAVIGATION_PULSE_COLOR
{255, 255, 255, 255}, // B_SHINE_COLOR
{0, 0, 0, 255}, // B_SHADOW_COLOR
{255, 255, 216, 255}, // B_TOOLTIP_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_TOOLTIP_TEXT_COLOR
{0, 0, 0, 255}, // B_WINDOW_TEXT_COLOR
{232, 232, 232, 255}, // B_WINDOW_INACTIVE_TAB_COLOR
{80, 80, 80, 255}, // B_WINDOW_INACTIVE_TEXT_COLOR
{224, 224, 224, 255}, // B_WINDOW_BORDER_COLOR
{232, 232, 232, 255}, // B_WINDOW_INACTIVE_BORDER_COLOR
{27, 82, 140, 255}, // B_CONTROL_MARK_COLOR
{255, 255, 255, 255}, // B_LIST_BACKGROUND_COLOR
{190, 190, 190, 255}, // B_LIST_SELECTED_BACKGROUND_COLOR
{0, 0, 0, 255}, // B_LIST_ITEM_TEXT_COLOR
{0, 0, 0, 255}, // B_LIST_SELECTED_ITEM_TEXT_COLOR
{216, 216, 216, 255}, // B_SCROLL_BAR_THUMB_COLOR
// 100...
{46, 204, 64, 255}, // B_SUCCESS_COLOR
{255, 65, 54, 255}, // B_FAILURE_COLOR
{}
};
const rgb_color* BPrivate::kDefaultColors = &_kDefaultColors[0];
namespace BPrivate {
/*! Fills the \a width, \a height, and \a colorSpace parameters according
to the window screen's mode.
Returns \c true if the mode is known.
*/
bool
get_mode_parameter(uint32 mode, int32& width, int32& height,
uint32& colorSpace)
{
switch (mode) {
case B_8_BIT_640x480:
case B_8_BIT_800x600:
case B_8_BIT_1024x768:
case B_8_BIT_1152x900:
case B_8_BIT_1280x1024:
case B_8_BIT_1600x1200:
colorSpace = B_CMAP8;
break;
case B_15_BIT_640x480:
case B_15_BIT_800x600:
case B_15_BIT_1024x768:
case B_15_BIT_1152x900:
case B_15_BIT_1280x1024:
case B_15_BIT_1600x1200:
colorSpace = B_RGB15;
break;
case B_16_BIT_640x480:
case B_16_BIT_800x600:
case B_16_BIT_1024x768:
case B_16_BIT_1152x900:
case B_16_BIT_1280x1024:
case B_16_BIT_1600x1200:
colorSpace = B_RGB16;
break;
case B_32_BIT_640x480:
case B_32_BIT_800x600:
case B_32_BIT_1024x768:
case B_32_BIT_1152x900:
case B_32_BIT_1280x1024:
case B_32_BIT_1600x1200:
colorSpace = B_RGB32;
break;
default:
return false;
}
switch (mode) {
case B_8_BIT_640x480:
case B_15_BIT_640x480:
case B_16_BIT_640x480:
case B_32_BIT_640x480:
width = 640; height = 480;
break;
case B_8_BIT_800x600:
case B_15_BIT_800x600:
case B_16_BIT_800x600:
case B_32_BIT_800x600:
width = 800; height = 600;
break;
case B_8_BIT_1024x768:
case B_15_BIT_1024x768:
case B_16_BIT_1024x768:
case B_32_BIT_1024x768:
width = 1024; height = 768;
break;
case B_8_BIT_1152x900:
case B_15_BIT_1152x900:
case B_16_BIT_1152x900:
case B_32_BIT_1152x900:
width = 1152; height = 900;
break;
case B_8_BIT_1280x1024:
case B_15_BIT_1280x1024:
case B_16_BIT_1280x1024:
case B_32_BIT_1280x1024:
width = 1280; height = 1024;
break;
case B_8_BIT_1600x1200:
case B_15_BIT_1600x1200:
case B_16_BIT_1600x1200:
case B_32_BIT_1600x1200:
width = 1600; height = 1200;
break;
}
return true;
}
void
get_workspaces_layout(uint32* _columns, uint32* _rows)
{
int32 columns = 1;
int32 rows = 1;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_WORKSPACE_LAYOUT);
status_t status;
if (link.FlushWithReply(status) == B_OK && status == B_OK) {
link.Read<int32>(&columns);
link.Read<int32>(&rows);
}
if (_columns != NULL)
*_columns = columns;
if (_rows != NULL)
*_rows = rows;
}
void
set_workspaces_layout(uint32 columns, uint32 rows)
{
if (columns < 1 || rows < 1)
return;
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_WORKSPACE_LAYOUT);
link.Attach<int32>(columns);
link.Attach<int32>(rows);
link.Flush();
}
} // namespace BPrivate
void
set_subpixel_antialiasing(bool subpix)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_SUBPIXEL_ANTIALIASING);
link.Attach<bool>(subpix);
link.Flush();
}
status_t
get_subpixel_antialiasing(bool* subpix)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_SUBPIXEL_ANTIALIASING);
int32 status = B_ERROR;
if (link.FlushWithReply(status) != B_OK || status < B_OK)
return status;
link.Read<bool>(subpix);
return B_OK;
}
void
set_hinting_mode(uint8 hinting)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_HINTING);
link.Attach<uint8>(hinting);
link.Flush();
}
status_t
get_hinting_mode(uint8* hinting)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_HINTING);
int32 status = B_ERROR;
if (link.FlushWithReply(status) != B_OK || status < B_OK)
return status;
link.Read<uint8>(hinting);
return B_OK;
}
void
set_average_weight(uint8 averageWeight)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_SUBPIXEL_AVERAGE_WEIGHT);
link.Attach<uint8>(averageWeight);
link.Flush();
}
status_t
get_average_weight(uint8* averageWeight)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_SUBPIXEL_AVERAGE_WEIGHT);
int32 status = B_ERROR;
if (link.FlushWithReply(status) != B_OK || status < B_OK)
return status;
link.Read<uint8>(averageWeight);
return B_OK;
}
void
set_is_subpixel_ordering_regular(bool subpixelOrdering)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_SUBPIXEL_ORDERING);
link.Attach<bool>(subpixelOrdering);
link.Flush();
}
status_t
get_is_subpixel_ordering_regular(bool* subpixelOrdering)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_SUBPIXEL_ORDERING);
int32 status = B_ERROR;
if (link.FlushWithReply(status) != B_OK || status < B_OK)
return status;
link.Read<bool>(subpixelOrdering);
return B_OK;
}
const color_map *
system_colors()
{
return BScreen(B_MAIN_SCREEN_ID).ColorMap();
}
status_t
set_screen_space(int32 index, uint32 space, bool stick)
{
int32 width;
int32 height;
uint32 depth;
if (!BPrivate::get_mode_parameter(space, width, height, depth))
return B_BAD_VALUE;
BScreen screen(B_MAIN_SCREEN_ID);
display_mode mode;
// TODO: What about refresh rate ?
// currently we get it from the current video mode, but
// this might be not so wise.
status_t status = screen.GetMode(index, &mode);
if (status < B_OK)
return status;
mode.virtual_width = width;
mode.virtual_height = height;
mode.space = depth;
return screen.SetMode(index, &mode, stick);
}
status_t
get_scroll_bar_info(scroll_bar_info *info)
{
if (info == NULL)
return B_BAD_VALUE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_SCROLLBAR_INFO);
int32 code;
if (link.FlushWithReply(code) == B_OK
&& code == B_OK) {
link.Read<scroll_bar_info>(info);
return B_OK;
}
return B_ERROR;
}
status_t
set_scroll_bar_info(scroll_bar_info *info)
{
if (info == NULL)
return B_BAD_VALUE;
BPrivate::AppServerLink link;
int32 code;
link.StartMessage(AS_SET_SCROLLBAR_INFO);
link.Attach<scroll_bar_info>(*info);
if (link.FlushWithReply(code) == B_OK
&& code == B_OK)
return B_OK;
return B_ERROR;
}
status_t
get_mouse_type(int32 *type)
{
BMessage command(IS_GET_MOUSE_TYPE);
BMessage reply;
status_t err = _control_input_server_(&command, &reply);
if (err != B_OK)
return err;
return reply.FindInt32("mouse_type", type);
}
status_t
set_mouse_type(int32 type)
{
BMessage command(IS_SET_MOUSE_TYPE);
BMessage reply;
status_t err = command.AddInt32("mouse_type", type);
if (err != B_OK)
return err;
return _control_input_server_(&command, &reply);
}
status_t
get_mouse_map(mouse_map *map)
{
BMessage command(IS_GET_MOUSE_MAP);
BMessage reply;
const void *data = 0;
ssize_t count;
status_t err = _control_input_server_(&command, &reply);
if (err == B_OK)
err = reply.FindData("mousemap", B_RAW_TYPE, &data, &count);
if (err != B_OK)
return err;
memcpy(map, data, count);
return B_OK;
}
status_t
set_mouse_map(mouse_map *map)
{
BMessage command(IS_SET_MOUSE_MAP);
BMessage reply;
status_t err = command.AddData("mousemap", B_RAW_TYPE, map,
sizeof(mouse_map));
if (err != B_OK)
return err;
return _control_input_server_(&command, &reply);
}
status_t
get_click_speed(bigtime_t *speed)
{
BMessage command(IS_GET_CLICK_SPEED);
BMessage reply;
status_t err = _control_input_server_(&command, &reply);
if (err != B_OK)
return err;
if (reply.FindInt64("speed", speed) != B_OK)
*speed = 500000;
return B_OK;
}
status_t
set_click_speed(bigtime_t speed)
{
BMessage command(IS_SET_CLICK_SPEED);
BMessage reply;
command.AddInt64("speed", speed);
return _control_input_server_(&command, &reply);
}
status_t
get_mouse_speed(int32 *speed)
{
BMessage command(IS_GET_MOUSE_SPEED);
BMessage reply;
status_t err = _control_input_server_(&command, &reply);
if (err != B_OK)
return err;
if (reply.FindInt32("speed", speed) != B_OK)
*speed = 65536;
return B_OK;
}
status_t
set_mouse_speed(int32 speed)
{
BMessage command(IS_SET_MOUSE_SPEED);
BMessage reply;
command.AddInt32("speed", speed);
return _control_input_server_(&command, &reply);
}
status_t
get_mouse_acceleration(int32 *speed)
{
BMessage command(IS_GET_MOUSE_ACCELERATION);
BMessage reply;
_control_input_server_(&command, &reply);
if (reply.FindInt32("speed", speed) != B_OK)
*speed = 65536;
return B_OK;
}
status_t
set_mouse_acceleration(int32 speed)
{
BMessage command(IS_SET_MOUSE_ACCELERATION);
BMessage reply;
command.AddInt32("speed", speed);
return _control_input_server_(&command, &reply);
}
status_t
get_key_repeat_rate(int32 *rate)
{
BMessage command(IS_GET_KEY_REPEAT_RATE);
BMessage reply;
_control_input_server_(&command, &reply);
if (reply.FindInt32("rate", rate) != B_OK)
*rate = 250000;
return B_OK;
}
status_t
set_key_repeat_rate(int32 rate)
{
BMessage command(IS_SET_KEY_REPEAT_RATE);
BMessage reply;
command.AddInt32("rate", rate);
return _control_input_server_(&command, &reply);
}
status_t
get_key_repeat_delay(bigtime_t *delay)
{
BMessage command(IS_GET_KEY_REPEAT_DELAY);
BMessage reply;
_control_input_server_(&command, &reply);
if (reply.FindInt64("delay", delay) != B_OK)
*delay = 200;
return B_OK;
}
status_t
set_key_repeat_delay(bigtime_t delay)
{
BMessage command(IS_SET_KEY_REPEAT_DELAY);
BMessage reply;
command.AddInt64("delay", delay);
return _control_input_server_(&command, &reply);
}
uint32
modifiers()
{
BMessage command(IS_GET_MODIFIERS);
BMessage reply;
int32 err, modifier;
_control_input_server_(&command, &reply);
if (reply.FindInt32("status", &err) != B_OK)
return 0;
if (reply.FindInt32("modifiers", &modifier) != B_OK)
return 0;
return modifier;
}
status_t
get_key_info(key_info *info)
{
BMessage command(IS_GET_KEY_INFO);
BMessage reply;
const void *data = 0;
int32 err;
ssize_t count;
_control_input_server_(&command, &reply);
if (reply.FindInt32("status", &err) != B_OK)
return B_ERROR;
if (reply.FindData("key_info", B_ANY_TYPE, &data, &count) != B_OK)
return B_ERROR;
memcpy(info, data, count);
return B_OK;
}
void
get_key_map(key_map **map, char **key_buffer)
{
_get_key_map(map, key_buffer, NULL);
}
void
_get_key_map(key_map **map, char **key_buffer, ssize_t *key_buffer_size)
{
BMessage command(IS_GET_KEY_MAP);
BMessage reply;
ssize_t map_count, key_count;
const void *map_array = 0, *key_array = 0;
if (key_buffer_size == NULL)
key_buffer_size = &key_count;
_control_input_server_(&command, &reply);
if (reply.FindData("keymap", B_ANY_TYPE, &map_array, &map_count) != B_OK) {
*map = 0; *key_buffer = 0;
return;
}
if (reply.FindData("key_buffer", B_ANY_TYPE, &key_array, key_buffer_size)
!= B_OK) {
*map = 0; *key_buffer = 0;
return;
}
*map = (key_map *)malloc(map_count);
memcpy(*map, map_array, map_count);
*key_buffer = (char *)malloc(*key_buffer_size);
memcpy(*key_buffer, key_array, *key_buffer_size);
}
status_t
get_keyboard_id(uint16 *id)
{
BMessage command(IS_GET_KEYBOARD_ID);
BMessage reply;
uint16 kid;
_control_input_server_(&command, &reply);
status_t err = reply.FindInt16("id", (int16 *)&kid);
if (err != B_OK)
return err;
*id = kid;
return B_OK;
}
status_t
get_modifier_key(uint32 modifier, uint32 *key)
{
BMessage command(IS_GET_MODIFIER_KEY);
BMessage reply;
uint32 rkey;
command.AddInt32("modifier", modifier);
_control_input_server_(&command, &reply);
status_t err = reply.FindInt32("key", (int32 *) &rkey);
if (err != B_OK)
return err;
*key = rkey;
return B_OK;
}
void
set_modifier_key(uint32 modifier, uint32 key)
{
BMessage command(IS_SET_MODIFIER_KEY);
BMessage reply;
command.AddInt32("modifier", modifier);
command.AddInt32("key", key);
_control_input_server_(&command, &reply);
}
void
set_keyboard_locks(uint32 modifiers)
{
BMessage command(IS_SET_KEYBOARD_LOCKS);
BMessage reply;
command.AddInt32("locks", modifiers);
_control_input_server_(&command, &reply);
}
status_t
_restore_key_map_()
{
BMessage message(IS_RESTORE_KEY_MAP);
BMessage reply;
return _control_input_server_(&message, &reply);
}
rgb_color
keyboard_navigation_color()
{
// Queries the app_server
return ui_color(B_KEYBOARD_NAVIGATION_COLOR);
}
int32
count_workspaces()
{
uint32 columns;
uint32 rows;
BPrivate::get_workspaces_layout(&columns, &rows);
return columns * rows;
}
void
set_workspace_count(int32 count)
{
int32 squareRoot = (int32)sqrt(count);
int32 rows = 1;
for (int32 i = 2; i <= squareRoot; i++) {
if (count % i == 0)
rows = i;
}
int32 columns = count / rows;
BPrivate::set_workspaces_layout(columns, rows);
}
int32
current_workspace()
{
int32 index = 0;
BPrivate::AppServerLink link;
link.StartMessage(AS_CURRENT_WORKSPACE);
int32 status;
if (link.FlushWithReply(status) == B_OK && status == B_OK)
link.Read<int32>(&index);
return index;
}
void
activate_workspace(int32 workspace)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_ACTIVATE_WORKSPACE);
link.Attach<int32>(workspace);
link.Attach<bool>(false);
link.Flush();
}
bigtime_t
idle_time()
{
bigtime_t idletime = 0;
BPrivate::AppServerLink link;
link.StartMessage(AS_IDLE_TIME);
int32 code;
if (link.FlushWithReply(code) == B_OK && code == B_OK)
link.Read<int64>(&idletime);
return idletime;
}
void
run_select_printer_panel()
{
if (be_roster == NULL)
return;
// Launches the Printer prefs app via the Roster
be_roster->Launch(PRNT_SIGNATURE_TYPE);
}
void
run_add_printer_panel()
{
// Launches the Printer prefs app via the Roster and asks it to
// add a printer
run_select_printer_panel();
BMessenger printerPanelMessenger(PRNT_SIGNATURE_TYPE);
printerPanelMessenger.SendMessage(PRINTERS_ADD_PRINTER);
}
void
run_be_about()
{
if (be_roster != NULL)
be_roster->Launch("application/x-vnd.Haiku-About");
}
void
set_focus_follows_mouse(bool follow)
{
// obviously deprecated API
set_mouse_mode(B_FOCUS_FOLLOWS_MOUSE);
}
bool
focus_follows_mouse()
{
return mouse_mode() == B_FOCUS_FOLLOWS_MOUSE;
}
void
set_mouse_mode(mode_mouse mode)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_MOUSE_MODE);
link.Attach<mode_mouse>(mode);
link.Flush();
}
mode_mouse
mouse_mode()
{
// Gets the mouse focus style, such as activate to click,
// focus to click, ...
mode_mouse mode = B_NORMAL_MOUSE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_MOUSE_MODE);
int32 code;
if (link.FlushWithReply(code) == B_OK && code == B_OK)
link.Read<mode_mouse>(&mode);
return mode;
}
void
set_focus_follows_mouse_mode(mode_focus_follows_mouse mode)
{
BPrivate::AppServerLink link;
link.StartMessage(AS_SET_FOCUS_FOLLOWS_MOUSE_MODE);
link.Attach<mode_focus_follows_mouse>(mode);
link.Flush();
}
mode_focus_follows_mouse
focus_follows_mouse_mode()
{
mode_focus_follows_mouse mode = B_NORMAL_FOCUS_FOLLOWS_MOUSE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_FOCUS_FOLLOWS_MOUSE_MODE);
int32 code;
if (link.FlushWithReply(code) == B_OK && code == B_OK)
link.Read<mode_focus_follows_mouse>(&mode);
return mode;
}
status_t
get_mouse(BPoint* screenWhere, uint32* buttons)
{
if (screenWhere == NULL && buttons == NULL)
return B_BAD_VALUE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_CURSOR_POSITION);
int32 code;
status_t ret = link.FlushWithReply(code);
if (ret != B_OK)
return ret;
if (code != B_OK)
return code;
if (screenWhere != NULL)
ret = link.Read<BPoint>(screenWhere);
else {
BPoint dummy;
ret = link.Read<BPoint>(&dummy);
}
if (ret != B_OK)
return ret;
if (buttons != NULL)
ret = link.Read<uint32>(buttons);
else {
uint32 dummy;
ret = link.Read<uint32>(&dummy);
}
return ret;
}
status_t
get_mouse_bitmap(BBitmap** bitmap, BPoint* hotspot)
{
if (bitmap == NULL && hotspot == NULL)
return B_BAD_VALUE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_CURSOR_BITMAP);
int32 code;
status_t status = link.FlushWithReply(code);
if (status != B_OK)
return status;
if (code != B_OK)
return code;
uint32 size = 0;
uint32 cursorWidth = 0;
uint32 cursorHeight = 0;
// if link.Read() returns an error, the same error will be returned on
// subsequent calls, so we'll check only the return value of the last call
link.Read<uint32>(&size);