|
1 | 1 | #include <X11/Xlib.h> |
2 | 2 | #include <X11/Xft/Xft.h> |
3 | 3 | #include <X11/Xresource.h> |
| 4 | +#include <X11/extensions/Xrandr.h> |
4 | 5 | #include <stdio.h> |
5 | 6 | #include <stdlib.h> |
6 | 7 | #include <signal.h> |
@@ -136,13 +137,28 @@ int main(int argc, char *argv[]) |
136 | 137 | XRES_INT(pos_y); |
137 | 138 | XRES_INT(corner); |
138 | 139 | XRES_INT(duration); |
| 140 | + XRES_INT(use_primary_monitor); |
139 | 141 |
|
140 | 142 | int screen = DefaultScreen(display); |
141 | 143 | Visual *visual = DefaultVisual(display, screen); |
142 | 144 | Colormap colormap = DefaultColormap(display, screen); |
143 | 145 |
|
| 146 | + int screen_x = 0; |
| 147 | + int screen_y = 0; |
144 | 148 | int screen_width = DisplayWidth(display, screen); |
145 | 149 | int screen_height = DisplayHeight(display, screen); |
| 150 | + if (use_primary_monitor) { |
| 151 | + int nMonitors; |
| 152 | + XRRMonitorInfo *info = XRRGetMonitors(display, RootWindow(display, screen), 1, &nMonitors); |
| 153 | + for (int i = 0; i < nMonitors; i++) { |
| 154 | + if (info[i].primary) { |
| 155 | + screen_x = info[i].x; |
| 156 | + screen_y = info[i].y; |
| 157 | + screen_width = info[i].width; |
| 158 | + screen_height = info[i].height; |
| 159 | + } |
| 160 | + } |
| 161 | + } |
146 | 162 |
|
147 | 163 | XSetWindowAttributes attributes; |
148 | 164 | attributes.override_redirect = True; |
@@ -181,16 +197,16 @@ int main(int argc, char *argv[]) |
181 | 197 | } |
182 | 198 | } |
183 | 199 |
|
184 | | - unsigned int x = pos_x; |
185 | | - unsigned int y = pos_y; |
| 200 | + unsigned int x = screen_x + pos_x; |
| 201 | + unsigned int y = screen_y + pos_y; |
186 | 202 | unsigned int text_height = font->ascent - font->descent; |
187 | 203 | unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding; |
188 | 204 |
|
189 | 205 | if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT) |
190 | | - x = screen_width - width - border_size * 2 - pos_x; |
| 206 | + x = screen_x + screen_width - width - border_size * 2 - pos_x; |
191 | 207 |
|
192 | 208 | if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT) |
193 | | - y = screen_height - height - border_size * 2 - pos_y; |
| 209 | + y = screen_y + screen_height - height - border_size * 2 - pos_y; |
194 | 210 |
|
195 | 211 | window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen), |
196 | 212 | CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); |
|
0 commit comments