Skip to content

Commit 2d6f770

Browse files
committed
refactor: Removed Windows compatibility
1 parent 79126c1 commit 2d6f770

25 files changed

+164
-530
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<div align="center">
22
<img src="./assets/logo.png" width="150" />
3-
<h3>A simple tool to take screenshots using your terminal</h3>
3+
<h3>A tool to take screenshots using your Linux terminal</h3>
44
</div>
55

6+
<br><br>
7+
## ANNOUNCEMENT:
8+
**I've decided to shutdown Windows compatibility, reason is, this tool is terminal friendly and Windows users usually don't, other user friendly tools are used, like the Windows 10 builtin "Win + Shift + S" command. The linux support will continue and I want to embrace Unix like OSs, hope you all understand me.**
9+
610
&nbsp;
711
## ❗️ Install:
812
Arch based:
@@ -29,6 +33,9 @@ make install
2933
## 🚀 Usage:
3034
**If you want to use the properly builded script, check <a href="https://github.com/z3oxs/ghost/releases">releases page</a>**
3135

36+
&nbsp;
37+
<div align="center">
38+
3239
| Command | Description |
3340
| ------------- | ------------------ |
3441
| f | Take fullscreen shot (include all monitors) |
@@ -40,6 +47,8 @@ make install
4047
| o | Outputs screenshot to stdout encoded as png |
4148
| u | Upload the screenshot to AnonFiles |
4249
| v | Show version |
50+
51+
</div>
4352

4453
&nbsp;
4554
### Example
@@ -55,10 +64,3 @@ ghost -s -c
5564
```bash
5665
ghost -f -o
5766
```
58-
59-
<br><br>
60-
## ❌ Troubleshooting:
61-
- If you're facing any "cc1.exe" error including "64-bit not implemented" (Windows):
62-
- Download [mingw-w64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z)
63-
- Extract and copy "mingw64" to "C:\"
64-
- Define or create "PATH" enviroment variable containing "C:\\mingw64\\bin\\"

cgo/checkOS.c

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

cgo/clipboard.c

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

cgo/displays.c

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#include "checkOS.c"
21
#include <stdio.h>
2+
#include <X11/Xlib.h>
3+
#include <X11/extensions/Xrandr.h>
4+
#include <X11/extensions/randr.h>
35

46
struct DisplayInfo {
57
int x;
@@ -8,72 +10,34 @@ struct DisplayInfo {
810
int h;
911
};
1012

11-
static struct DisplayInfo displayInfos[10];
13+
struct DisplayInfo * getDisplays() {
14+
static struct DisplayInfo displayInfos[10];
1215

13-
#if defined (UNIX)
14-
#include <X11/Xlib.h>
15-
#include <X11/extensions/Xrandr.h>
16-
#include <X11/extensions/randr.h>
17-
18-
struct DisplayInfo * getDisplays() {
19-
Display * dpy = XOpenDisplay(NULL);
20-
XRRScreenResources * screen = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
21-
XRRCrtcInfo * crtcInfo;
22-
int ncrtc = screen -> ncrtc;
23-
int turns = 0;
24-
25-
for (int i = 0; i < ncrtc; i++) {
26-
crtcInfo = XRRGetCrtcInfo(dpy, screen, screen -> crtcs[i]);
27-
28-
if (crtcInfo -> width != 0) {
29-
struct DisplayInfo displayInfo;
30-
31-
displayInfo.x = crtcInfo -> x;
32-
displayInfo.y = crtcInfo -> y;
33-
displayInfo.w = crtcInfo -> width;
34-
displayInfo.h = crtcInfo -> height;
35-
36-
displayInfos[turns] = displayInfo;
37-
turns += 1;
38-
}
39-
40-
XRRFreeCrtcInfo(crtcInfo);
41-
}
42-
43-
XRRFreeScreenResources(screen);
16+
Display * dpy = XOpenDisplay(NULL);
17+
XRRScreenResources * screen = XRRGetScreenResources(dpy, DefaultRootWindow(dpy));
18+
XRRCrtcInfo * crtcInfo;
19+
int ncrtc = screen -> ncrtc;
20+
int turns = 0;
4421

45-
return displayInfos;
46-
}
47-
#endif
22+
for (int i = 0; i < ncrtc; i++) {
23+
crtcInfo = XRRGetCrtcInfo(dpy, screen, screen -> crtcs[i]);
4824

49-
#if defined (WINDOWS)
50-
#include <windows.h>
25+
if (crtcInfo -> width != 0) {
26+
struct DisplayInfo displayInfo;
5127

52-
int turns = 0;
28+
displayInfo.x = crtcInfo -> x;
29+
displayInfo.y = crtcInfo -> y;
30+
displayInfo.w = crtcInfo -> width;
31+
displayInfo.h = crtcInfo -> height;
5332

54-
BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprc, LPARAM dwData) {
55-
MONITORINFO info;
56-
57-
info.cbSize = sizeof(info);
58-
59-
if (GetMonitorInfo(hMon, &info)) {
60-
struct DisplayInfo displayInfo;
61-
62-
displayInfo.x = info.rcMonitor.left;
63-
displayInfo.y = info.rcMonitor.top;
64-
displayInfo.w = info.rcMonitor.right;
65-
displayInfo.h = info.rcMonitor.bottom;
66-
6733
displayInfos[turns] = displayInfo;
6834
turns += 1;
6935
}
70-
71-
return TRUE;
72-
}
7336

74-
struct DisplayInfo * getDisplays() {
75-
EnumDisplayMonitors(NULL, NULL, MonitorEnum, 0);
76-
77-
return displayInfos;
37+
XRRFreeCrtcInfo(crtcInfo);
7838
}
79-
#endif
39+
40+
XRRFreeScreenResources(screen);
41+
42+
return displayInfos;
43+
}

cgo/mouse.c

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include <stdio.h>
22
#include <stdlib.h>
3-
#include "checkOS.c"
3+
#include <X11/Xlib.h>
4+
#include <X11/Xutil.h>
5+
#include <X11/X.h>
6+
#include <X11/cursorfont.h>
47

58
struct MousePosition {
69
int x1,
@@ -11,99 +14,92 @@ struct MousePosition {
1114

1215
static struct MousePosition mousePosition[1];
1316

14-
#if defined (UNIX)
15-
#include <X11/Xlib.h>
16-
#include <X11/Xutil.h>
17-
#include <X11/X.h>
18-
#include <X11/cursorfont.h>
17+
struct MousePosition *getMouse(void) {
18+
Display *display = XOpenDisplay(NULL);
19+
Window root = XRootWindow(display, 0);
20+
XEvent event;
1921

20-
struct MousePosition *getMouse(void) {
21-
Display *display = XOpenDisplay(NULL);
22-
Window root = XRootWindow(display, 0);
23-
XEvent event;
22+
Cursor cursor = XCreateFontCursor(display, XC_crosshair);
23+
XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
2424

25-
Cursor cursor = XCreateFontCursor(display, XC_crosshair);
26-
XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
25+
for (int i = 0; i < 2; i++) {
26+
XWindowEvent(display, root, ButtonPressMask | KeyPressMask, &event);
2727

28-
for (int i = 0; i < 2; i++) {
29-
XWindowEvent(display, root, ButtonPressMask | KeyPressMask, &event);
28+
switch (event.type) {
29+
case ButtonPress:
30+
switch (event.xbutton.button) {
31+
case Button1:
32+
if (i == 0) {
33+
mousePosition->x1 = event.xbutton.x_root;
34+
mousePosition->y1 = event.xbutton.y_root;
3035

31-
switch (event.type) {
32-
case ButtonPress:
33-
switch (event.xbutton.button) {
34-
case Button1:
35-
if (i == 0) {
36-
mousePosition->x1 = event.xbutton.x_root;
37-
mousePosition->y1 = event.xbutton.y_root;
36+
} else {
37+
mousePosition->x2 = event.xbutton.x_root;
38+
mousePosition->y2 = event.xbutton.y_root;
3839

39-
} else {
40-
mousePosition->x2 = event.xbutton.x_root;
41-
mousePosition->y2 = event.xbutton.y_root;
40+
}
4241

43-
}
42+
break;
43+
}
4444

45-
break;
46-
}
45+
break;
4746

48-
break;
49-
50-
default:
51-
i--;
52-
}
47+
default:
48+
i--;
5349
}
50+
}
5451

55-
XUngrabPointer(display, CurrentTime);
52+
XUngrabPointer(display, CurrentTime);
5653

57-
return mousePosition;
58-
}
54+
return mousePosition;
55+
}
5956

60-
struct MousePosition *getMouseAndKeyboard(void) {
61-
Display *display = XOpenDisplay(NULL);
62-
Window root = XRootWindow(display, 0);
63-
XEvent event;
57+
struct MousePosition *getMouseAndKeyboard(void) {
58+
Display *display = XOpenDisplay(NULL);
59+
Window root = XRootWindow(display, 0);
60+
XEvent event;
6461

65-
Cursor cursor = XCreateFontCursor(display, XC_crosshair);
66-
XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
67-
XGrabKeyboard(display, root, KeyPressMask, GrabModeAsync, GrabModeAsync, CurrentTime);
62+
Cursor cursor = XCreateFontCursor(display, XC_crosshair);
63+
XGrabPointer(display, root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
64+
XGrabKeyboard(display, root, KeyPressMask, GrabModeAsync, GrabModeAsync, CurrentTime);
6865

69-
for (int i = 0; i < 2; i++) {
70-
XWindowEvent(display, root, ButtonPressMask | KeyPressMask, &event);
66+
for (int i = 0; i < 2; i++) {
67+
XWindowEvent(display, root, ButtonPressMask | KeyPressMask, &event);
7168

72-
switch (event.type) {
73-
case ButtonPress:
74-
switch (event.xbutton.button) {
75-
case Button1:
76-
if (i == 0) {
77-
mousePosition->x1 = event.xbutton.x_root;
78-
mousePosition->y1 = event.xbutton.y_root;
69+
switch (event.type) {
70+
case ButtonPress:
71+
switch (event.xbutton.button) {
72+
case Button1:
73+
if (i == 0) {
74+
mousePosition->x1 = event.xbutton.x_root;
75+
mousePosition->y1 = event.xbutton.y_root;
7976

80-
} else {
81-
mousePosition->x2 = event.xbutton.x_root;
82-
mousePosition->y2 = event.xbutton.y_root;
77+
} else {
78+
mousePosition->x2 = event.xbutton.x_root;
79+
mousePosition->y2 = event.xbutton.y_root;
8380

84-
}
81+
}
8582

86-
break;
87-
}
83+
break;
84+
}
8885

89-
break;
86+
break;
9087

91-
case KeyPress:
92-
switch (event.xkey.keycode) {
93-
case 9:
94-
exit(3);
88+
case KeyPress:
89+
switch (event.xkey.keycode) {
90+
case 9:
91+
exit(3);
9592

96-
break;
97-
}
98-
99-
default:
100-
i--;
101-
}
93+
break;
94+
}
95+
96+
default:
97+
i--;
10298
}
99+
}
103100

104-
XUngrabPointer(display, CurrentTime);
105-
XUngrabKeyboard(display, CurrentTime);
101+
XUngrabPointer(display, CurrentTime);
102+
XUngrabKeyboard(display, CurrentTime);
106103

107-
return mousePosition;
108-
}
109-
#endif
104+
return mousePosition;
105+
}

0 commit comments

Comments
 (0)