我正在运行双屏设置,并且大部分时间都禁用了触控板(包括隐藏鼠标指针)。当我重新启用触控板(并再次显示鼠标指针)时,我已经忘记了指针之前所在的位置。
我正在寻找一种工具来突出显示当前鼠标位置(例如,通过一个圆圈)。理想情况下,这将是在短时间内闪烁圆圈的单个命令。
我知道xdotool可以找到当前位置,但没有突出显示;此外,key-mon不提供此功能。我也读过它cairo composition manager提供了这样的功能,但我想知道是否有一个更小的工具来实现这一点。
如果没有这样的工具:使用 提供的数据在光标周围显示这样一个圆圈的最简单方法是 xdotool getmouselocation什么?
如果这是相关的:我不使用桌面环境,只使用 xmonad窗口管理器。
Mar*_*oij 27
虽然我喜欢Mikeserv对聪明的回答,但它的缺点是它会创建一个窗口,该窗口“窃取”焦点并且必须被点击。我也发现这个时间只是略微开始太长:约0.2至0.3秒,也就是稍稍太慢了“平稳”的经验。
我终于开始深入研究 XLib,并拼凑了一个基本的 C 程序来做到这一点。视觉效果大致类似于 Windows (XP) 所具有的(来自内存)。它不是很漂亮,但它有效 ;-) 它不会“窃取”焦点,几乎是瞬时开始的,您可以单击“通过”它。
你可以用cc find-cursor.c -o find-cursor -lX11 -lXext -lXfixes. 顶部有一些变量,您可以调整以更改大小、速度等。
我在https://github.com/arp242/find-cursor 上将其作为程序发布。我建议您使用此版本,因为它具有以下脚本所没有的一些改进(例如命令行参数和单击“通过”窗口的能力)。由于它的简单性,我保留了下面的原样。
/*
* https://github.com/arp242/find-cursor
* Copyright © 2015 Martin Tournoij <martin@arp242.net>
* See below for full copyright
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
// Some variables you can play with :-)
int size = 220;
int step = 40;
int speed = 400;
int line_width = 2;
char color_name[] = "black";
int main(int argc, char* argv[]) {
// Setup display and such
char *display_name = getenv("DISPLAY");
if (!display_name) {
fprintf(stderr, "%s: cannot connect to X server '%s'\n", argv[0], display_name);
exit(1);
}
Display *display = XOpenDisplay(display_name);
int screen = DefaultScreen(display);
// Get the mouse cursor position
int win_x, win_y, root_x, root_y = 0;
unsigned int mask = 0;
Window child_win, root_win;
XQueryPointer(display, XRootWindow(display, screen),
&child_win, &root_win,
&root_x, &root_y, &win_x, &win_y, &mask);
// Create a window at the mouse position
XSetWindowAttributes window_attr;
window_attr.override_redirect = 1;
Window window = XCreateWindow(display, XRootWindow(display, screen),
root_x - size/2, root_y - size/2, // x, y position
size, size, // width, height
0, // border width
DefaultDepth(display, screen), // depth
CopyFromParent, // class
DefaultVisual(display, screen), // visual
CWOverrideRedirect, // valuemask
&window_attr // attributes
);
XMapWindow(display, window);
XStoreName(display, window, "find-cursor");
XClassHint *class = XAllocClassHint();
class->res_name = "find-cursor";
class->res_class = "find-cursor";
XSetClassHint(display, window, class);
XFree(class);
// Keep the window on top
XEvent e;
memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage;
e.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", False);
e.xclient.display = display;
e.xclient.window = window;
e.xclient.format = 32;
e.xclient.data.l[0] = 1;
e.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_STAYS_ON_TOP", False);
XSendEvent(display, XRootWindow(display, screen), False, SubstructureRedirectMask, &e);
XRaiseWindow(display, window);
XFlush(display);
// Prepare to draw on this window
XGCValues values;
values.graphics_exposures = False;
unsigned long valuemask = 0;
GC gc = XCreateGC(display, window, valuemask, &values);
Colormap colormap = DefaultColormap(display, screen);
XColor color;
XAllocNamedColor(display, colormap, color_name, &color, &color);
XSetForeground(display, gc, color.pixel);
XSetLineAttributes(display, gc, line_width, LineSolid, CapButt, JoinBevel);
// Draw the circles
for (int i=1; i<=size; i+=step) {
XDrawArc(display, window, gc,
size/2 - i/2, size/2 - i/2, // x, y position
i, i, // Size
0, 360 * 64); // Make it a full circle
XSync(display, False);
usleep(speed * 100);
}
XFreeGC(display, gc);
XCloseDisplay(display);
}
/*
* The MIT License (MIT)
*
* Copyright © 2015 Martin Tournoij
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* The software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. In no event shall the
* authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising
* from, out of or in connection with the software or the use or other dealings
* in the software.
*/
Run Code Online (Sandbox Code Playgroud)
以下内容可能对您有用:
#!/bin/sh
unset X Y; sleep 1
eval "$(xdotool getmouselocation -shell 2>/dev/null)"
for n in X Y; do : "$(($n-=$n>25?25:$n))"; done
xwd -root -silent |
xv - -crop "$X" "$Y" 50 50 \
-geometry "50x50+$X+$Y" \
-nodecor -viewonly -rv -quit
Run Code Online (Sandbox Code Playgroud)
这取决于三个工具xv,xwd和xdotool。前两个是非常常见的X实用程序,第三个我有理由相信你已经有了。
之后sleep荷兰国际集团一秒钟,xdotool写鼠标的当前坐标其在一个eval友好的标准输出-shell一样的格式:
X=[num]
Y=[num]
windowID=[num]
Run Code Online (Sandbox Code Playgroud)
eval相应地设置 shell 变量,for循环从每个$X和$Y的值中减去即将显示的图像大小的一半,或者,如果任一值小于 25,则将它们设置为 0。
xwd将根窗口通过管道转储到xv,将鼠标位置周围的图像裁剪为 50x50 的图像大小,并在没有任何窗口管理器装饰的小窗口中显示当前鼠标光标下的图像的负片。
最终结果是这样的:

...虽然我猜我的鼠标光标没有出现在屏幕截图中。不过请放心,当我拍照时,它就在那里的白框上方。
您可以在图像中看到我如何将它编写为 shell 函数并将其作为背景。主要是因为这个原因,那里有一个sleep-RETURN如果你已经在底部,按下键将滚动终端,并且xwd在终端滚动之前足够快地抓住它的屏幕图片 - 这将抵消我的图像有点负面,我不喜欢它。
无论如何,因为xv同时使用-viewonly和-quit开关运行,所以只要单击鼠标按钮或按下键盘键,它就会消失 - 但会一直存在,直到您这样做为止。
毫无疑问,你可以用ImageMagick甚至xv单独做更复杂的事情- 但我只是在鼠标光标下做了一个小的负框。您可以在xv此处找到文档以及xwdin的文档man xwd。
| 归档时间: |
|
| 查看次数: |
8488 次 |
| 最近记录: |