Skip to content

Commit 9210599

Browse files
authored
Merge pull request #443 from go-vgo/bitmap-pr
Refactor the Alert() code and remove some code
2 parents 897af2a + 8defbda commit 9210599

File tree

12 files changed

+53
-1274
lines changed

12 files changed

+53
-1274
lines changed

base/snprintf.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

base/snprintf_c.h

Lines changed: 0 additions & 1019 deletions
This file was deleted.

base/types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
/* Some generic, cross-platform types. */
1111

12+
#ifdef RobotGo_64
13+
typedef int64_t intptr;
14+
typedef uint64_t uintptr;
15+
#else
16+
typedef int32_t intptr;
17+
typedef uint32_t uintptr; // Unsigned pointer integer
18+
#endif
19+
1220
struct _MMPoint {
1321
size_t x;
1422
size_t y;

examples/window/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ import (
1919

2020
func alert() {
2121
// show Alert Window
22-
abool := robotgo.ShowAlert("hello", "robotgo")
22+
abool := robotgo.Alert("hello", "robotgo")
2323
if abool {
2424
fmt.Println("ok@@@", "ok")
2525
}
26-
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
27-
26+
robotgo.Alert("hello", "robotgo", "Ok", "Cancel")
2827
}
2928

3029
func get() {

mouse/goMouse.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,9 @@
1313

1414
// Global delays.
1515
int mouseDelay = 0;
16-
// int keyboardDelay = 10;
17-
18-
19-
// int CheckMouseButton(const char * const b,
20-
// MMMouseButton * const button){
21-
// if (!button) return -1;
22-
23-
// if (strcmp(b, "left") == 0) {
24-
// *button = LEFT_BUTTON;
25-
// }
26-
// else if (strcmp(b, "right") == 0) {
27-
// *button = RIGHT_BUTTON;
28-
// }
29-
// else if (strcmp(b, "middle") == 0) {
30-
// *button = CENTER_BUTTON;
31-
// } else {
32-
// return -2;
33-
// }
34-
35-
// return 0;
36-
// }
3716

3817
int move_mouse(int32_t x, int32_t y){
3918
MMPointInt32 point;
40-
// int x = 103;
41-
// int y = 104;
4219
point = MMPointInt32Make(x, y);
4320
moveMouse(point);
4421

@@ -47,16 +24,11 @@ int move_mouse(int32_t x, int32_t y){
4724

4825

4926
int drag_mouse(int32_t x, int32_t y, MMMouseButton button){
50-
// const size_t x = 10;
51-
// const size_t y = 20;
52-
// MMMouseButton button = LEFT_BUTTON;
53-
5427
MMPointInt32 point;
5528
point = MMPointInt32Make(x, y);
5629
dragMouse(point, button);
5730
microsleep(mouseDelay);
5831

59-
// printf("%s\n", "gyp-----");
6032
return 0;
6133
}
6234

@@ -73,15 +45,10 @@ bool move_mouse_smooth(int32_t x, int32_t y, double lowSpeed,
7345

7446
MMPointInt32 get_mouse_pos(){
7547
MMPointInt32 pos = getMousePos();
76-
77-
// Return object with .x and .y.
78-
// printf("%zu\n%zu\n", pos.x, pos.y );
7948
return pos;
8049
}
8150

8251
int mouse_click(MMMouseButton button, bool doubleC){
83-
// MMMouseButton button = LEFT_BUTTON;
84-
// bool doubleC = false;
8552
if (!doubleC) {
8653
clickMouse(button);
8754
} else {
@@ -94,7 +61,6 @@ int mouse_click(MMMouseButton button, bool doubleC){
9461
}
9562

9663
int mouse_toggle(char* d, MMMouseButton button){
97-
// MMMouseButton button = LEFT_BUTTON;
9864
bool down = false;
9965
if (strcmp(d, "down") == 0) {
10066
down = true;
@@ -111,9 +77,7 @@ int mouse_toggle(char* d, MMMouseButton button){
11177
}
11278

11379
int set_mouse_delay(size_t val){
114-
// int val = 10;
11580
mouseDelay = val;
116-
11781
return 0;
11882
}
11983

@@ -125,15 +89,13 @@ int scroll(int x, int y, int msDelay){
12589
}
12690

12791
int scroll_mouse(size_t scrollMagnitude, char *s){
128-
// int scrollMagnitude = 20;
12992
MMMouseWheelDirection scrollDirection;
13093

13194
if (strcmp(s, "up") == 0) {
13295
scrollDirection = DIRECTION_UP;
13396
} else if (strcmp(s, "down") == 0) {
13497
scrollDirection = DIRECTION_DOWN;
13598
} else {
136-
// return "Invalid scroll direction specified.";
13799
return 1;
138100
}
139101

robotgo.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,30 +1214,26 @@ ____ __ ____ __ .__ __. _______ ______ ____ __ ____
12141214
12151215
*/
12161216

1217-
// ShowAlert show a alert window
1218-
// Displays alert with the attributes.
1219-
// If cancel button is not given, only the default button is displayed
1220-
//
1221-
// Examples:
1222-
// robotgo.ShowAlert("hi", "window", "ok", "cancel")
1223-
func ShowAlert(title, msg string, args ...string) bool {
1217+
func alertArgs(args ...string) (string, string) {
12241218
var (
1225-
// title string
1226-
// msg string
12271219
defaultBtn = "Ok"
12281220
cancelBtn = "Cancel"
12291221
)
12301222

12311223
if len(args) > 0 {
1232-
// title = args[0]
1233-
// msg = args[1]
12341224
defaultBtn = args[0]
12351225
}
12361226

12371227
if len(args) > 1 {
12381228
cancelBtn = args[1]
12391229
}
12401230

1231+
return defaultBtn, cancelBtn
1232+
}
1233+
1234+
func showAlert(title, msg string, args ...string) bool {
1235+
defaultBtn, cancelBtn := alertArgs(args...)
1236+
12411237
cTitle := C.CString(title)
12421238
cMsg := C.CString(msg)
12431239
defaultButton := C.CString(defaultBtn)

robotgo_mac_win.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,13 @@ func ActivePID(pid int32, args ...int) error {
5555
func DisplaysNum() int {
5656
return getNumDisplays()
5757
}
58+
59+
// Alert show a alert window
60+
// Displays alert with the attributes.
61+
// If cancel button is not given, only the default button is displayed
62+
//
63+
// Examples:
64+
// robotgo.Alert("hi", "window", "ok", "cancel")
65+
func Alert(title, msg string, args ...string) bool {
66+
return showAlert(title, msg, args...)
67+
}

robotgo_x11.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package robotgo
1515

1616
import (
1717
"errors"
18+
"fmt"
1819
"log"
1920

2021
"github.com/robotn/xgb"
@@ -172,3 +173,25 @@ func DisplaysNum() int {
172173

173174
return int(reply.Number)
174175
}
176+
177+
// Alert show a alert window
178+
// Displays alert with the attributes.
179+
// If cancel button is not given, only the default button is displayed
180+
//
181+
// Examples:
182+
// robotgo.Alert("hi", "window", "ok", "cancel")
183+
func Alert(title, msg string, args ...string) bool {
184+
defaultBtn, cancelBtn := alertArgs(args...)
185+
c := `xmessage -center ` + msg +
186+
` -title ` + title + ` -buttons ` + defaultBtn + ":0," + cancelBtn + ":1" + ` -default Ok`
187+
out, err := Run(c)
188+
if err != nil {
189+
fmt.Println("Alert: ", err, ". ", string(out))
190+
return false
191+
}
192+
193+
if string(out) == "1" {
194+
return false
195+
}
196+
return true
197+
}

screen/screengrab_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ MMBitmapRef copyMMBitmapFromDisplayInRect(MMRectInt32 rect, int32_t display_id)
9595
if (display_id == -1) {
9696
screen = GetDC(NULL); /* Get entire screen */
9797
} else {
98-
screen = GetDC((HWND) display_id);
98+
screen = GetDC((HWND) (uintptr) display_id);
9999
}
100100
if (screen == NULL) { return NULL; }
101101

window/alert.h

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)