Commit cdbf8df 1 parent 483b46d commit cdbf8df Copy full SHA for cdbf8df
File tree 3 files changed +65
-1
lines changed
3 files changed +65
-1
lines changed Original file line number Diff line number Diff line change 2
2
#include < nan.h>
3
3
#include < v8.h>
4
4
#include < vector>
5
+ #include " string.h"
5
6
#include " mouse.h"
6
7
#include " deadbeef_rand.h"
7
8
#include " keypress.h"
10
11
#include " MMBitmap.h"
11
12
#include " snprintf.h"
12
13
#include " microsleep.h"
14
+ #include " xdisplay.h"
13
15
14
16
using namespace v8 ;
15
17
@@ -678,6 +680,26 @@ NAN_METHOD(getScreenSize)
678
680
info.GetReturnValue ().Set (obj);
679
681
}
680
682
683
+ NAN_METHOD (getXDisplayName)
684
+ {
685
+ NanScope ();
686
+ NanReturnValue (NanNew<String>(getXDisplay ()));
687
+ }
688
+
689
+ NAN_METHOD (setXDisplayName)
690
+ {
691
+ NanScope ();
692
+
693
+ // Convert arg to c-string
694
+ // NOTE: surely better way to go from v8::String to char* ?
695
+ std::string name =
696
+ std::string (*v8::String::Utf8Value (args[0 ]->ToString ()));
697
+ char *display_name = strdup (name.c_str ());
698
+
699
+ setXDisplay (display_name);
700
+ NanReturnUndefined ();
701
+ }
702
+
681
703
NAN_METHOD (captureScreen)
682
704
{
683
705
size_t x;
@@ -850,6 +872,12 @@ NAN_MODULE_INIT(InitAll)
850
872
851
873
Nan::Set (target, Nan::New (" getColor" ).ToLocalChecked (),
852
874
Nan::GetFunction (Nan::New<FunctionTemplate>(getColor)).ToLocalChecked ());
875
+
876
+ Nan::Set (target, Nan::New (" getXDisplayName" ).ToLocalChecked (),
877
+ Nan::GetFunction (Nan::New<FunctionTemplate>(getXDisplayName)).ToLocalChecked ());
878
+
879
+ Nan::Set (target, Nan::New (" setXDisplayName" ).ToLocalChecked (),
880
+ Nan::GetFunction (Nan::New<FunctionTemplate>(setXDisplayName)).ToLocalChecked ());
853
881
}
854
882
855
883
NODE_MODULE (robotjs, InitAll)
Original file line number Diff line number Diff line change 4
4
5
5
static Display * mainDisplay = NULL ;
6
6
static int registered = 0 ;
7
+ static char * display_name = ":0.0" ;
8
+ static int display_name_changed = 0 ;
7
9
8
10
Display * XGetMainDisplay (void )
9
11
{
12
+ /* Close the display if display_name has changed */
13
+ if (display_name_changed ) {
14
+ XCloseMainDisplay ();
15
+ }
16
+ display_name_changed = 0 ;
17
+
10
18
if (mainDisplay == NULL ) {
11
- mainDisplay = XOpenDisplay (NULL );
19
+ /* First try the user set display_name */
20
+ mainDisplay = XOpenDisplay (display_name );
21
+
22
+ /* Then try using environment variable DISPLAY */
23
+ if (mainDisplay == NULL ) {
24
+ mainDisplay = XOpenDisplay (NULL );
25
+ }
12
26
13
27
if (mainDisplay == NULL ) {
14
28
fputs ("Could not open main display\n" , stderr );
@@ -28,3 +42,13 @@ void XCloseMainDisplay(void)
28
42
mainDisplay = NULL ;
29
43
}
30
44
}
45
+
46
+ char * getXDisplay (void )
47
+ {
48
+ return display_name ;
49
+ }
50
+
51
+ void setXDisplay (char * name ) {
52
+ display_name = name ;
53
+ display_name_changed = 1 ;
54
+ }
Original file line number Diff line number Diff line change @@ -14,4 +14,16 @@ Display *XGetMainDisplay(void);
14
14
/* Closes the main display if it is open, or does nothing if not. */
15
15
void XCloseMainDisplay (void );
16
16
17
+ #ifdef __cplusplus
18
+ extern "C"
19
+ {
20
+ #endif
21
+
22
+ char * getXDisplay (void );
23
+ void setXDisplay (char * name );
24
+
25
+ #ifdef __cplusplus
26
+ }
27
+ #endif
28
+
17
29
#endif /* XDISPLAY_H */
You can’t perform that action at this time.
0 commit comments