I want to write an extension that does the opposite of the "focus-follows mouse" setting in GNOME Shell: I want to make my pointer move to the center of the currently focused window.
Can this be done in a GNOME Shell extension? I see some GNOME code that wraps xfixes cursor, but I can't find any references to programmatic pointer updates in either the core Javascript or any existing extensions. (Am I just bad at Google?)
Valid answers include (1) example code that does it or (2) citation of a canonical source that says it can't be done.
Found this code in overview.js
Gdk = imports.gi.Gdk
let display = Gdk.Display.get_default();
let deviceManager = display.get_device_manager();
let pointer = deviceManager.get_client_pointer();
let [screen, pointerX, pointerY] = pointer.get_position();
pointer.warp(screen, 10, 10);
Are you willing to write your own script? If you are, I have found three tools, which, if used together, can get the job done for you.
First, use xprop to get the PID of the window you have clicked on.
Next, use xwininfo to get the dimensions and position information of the window based on its process ID.
Finally, use xdotool to calculate the center position of said window and move the cursor to that exact position.
Hope this helps. I don't have enough time write now to write the script (sorry), but this should be enough to get you started.
EDIT: Based on your comment, you want to stay in GNOME js. Totally understandable. You can call xdotool (which is the most efficient way of changing the position of the cursor on screen) from within GNOME js by use of something like:
const Util = imports.misc.util;
Util.spawn(['/bin/bash', '-c', "xrandr --query | awk 'something'"]) # replace the code here wih your own
This code was found at this thread.
Related
Could someone share how can i create tui like this one with input boxex and search ?
What do i need?
Normally programmers use a ready to use library like ncurses.
You can also do it by hand if you really have to much time. To get for example the border lines of a dialog window you have to take a look at the current code page your terminal is emulating, for example: Code Page 850. As you can see, you will find single and double line boarders and also crossings and so on. Now you have to move your cursor to a given position, print that char from the code page and ... lots of work. Moving cursors itself can also be done by simple chars from your emulated terminal by using escape codes.
As said: Instead of doing it all by hand, simply use a lib like ncurses.
You can use some python libraries like pyTermTk or textual, there is wide selection of
libraries to choose from.
I'd like to script opening a workspace with the 'next' available number and then have open in that workspace maybe a two windows each already pointed at a specific view. Any pointers on how to do that? Is i3 actually scriptable in this regard? I have only just started using i3 and loving it, just want to now have it do things I need on a regular basis ;-)
All of i3's "scripting" that isn't already in the config is done through i3-msg
i3-msg sends messages to i3 window manager. It's mostly config lines(or IPC, which is a bit harder).
How can I open a work space from the command line in i3
How do you open it in your config?
bindsym Mod4+1 workspace $ws1
Something like that right? Now, using i3-msg to move to workspace 1:
i3-msg workspace 1
Simple, right?
The rest of your question is pretty unclear, but I'll do my best:
I'd like to script opening a workspace with the "next" available number"
How you'll start out with doing that is(after doing man i3-msg):
i3-msg -t get_workspaces
This returns a json(if you've done any coding you'll feel warm inside and if not you're going to be scared by the output). Then I'm going to ask you to read up on this:
https://i3wm.org/docs/ipc.html#_receiving_replies_from_i3
Using jq or something like json.sh to parse through the output with bash, you should get which workspaces are "active", example:
[{"num":3,"name":"3","visible":true,"focused":false,"rect":{"x":0,"y":0,"width":1920,"height":1080},"output":"HDMI-1","urgent":false},{"num":2,"name":"2","visible":true,"focused":false,"rect":{"x":3520,"y":0,"width":1920,"height":1080},"output":"VGA-1","urgent":false},{"num":1,"name":"1","visible":true,"focused":true,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false},{"num":5,"name":"5","visible":false,"focused":false,"rect":{"x":1920,"y":32,"width":1600,"height":868},"output":"eDP-1","urgent":false}]
Reading through the website I gave you, you can see, workspaces 1,2,3 and 5 are "active" aka have windows in them. After parsing the actual json you'll end up with an array or something of this. If you want to spawn on 4(the real "next" desktop) or 6 (aka biggest number + 1) is up to you. You didn't mention what you want to script it in, so I'll leave that to you to figure out.
maybe two windows each already pointed at a specific view
I'm not sure what you mean. You probably want 2 windows of X(we'll use a terminal in this case) in the workspace we've determined as "next" ?
Let's go back to i3-msg for a bit.
Imagine you doing whatever you're trying to do, manually, as a list of commands you're firing to i3.
"Go to workspace X" : i3-msg workspace 4
"Spawn a program called kitty there": kitty
"Split vertically and spawn another program": i3-msg split v
"Spawn another kitty window": kitty
After that you can get back to your current workspace(I suggest saving it in a variable and just reusing i3-msg workspace $curr_workspace).
As I said, the question wasn't about the actual scripting so I left that out to figure it out on your own, but don't hesitate to ask a concrete question under the bash tag. :). Hopefully I didn't completely misunderstand your question.
Welcome to the i3 community.
#Nephilim's post is excellent. Just to add a trick to the toolbox...
Sometimes you might want to script some action relative to a particular window. Like:
Give me a test environment next to this browser.
You can get the window ID by running xwininfo and clicking the window that you want to anchor your automation to. The window ID can be used as a parameter to i3-msg.
For example, running the command below will let you select a window and then will set that window's width to 1000:
i3-msg "[id=$(
xwininfo \
| sed -n 's/.*Window id: \(0x[0-9a-f]*\).*/\1/p'
)] resize set 1000"
I want to know if anyone does know a way to dump or copy the whole lot of viewable messages in a xterm window on linux. The very important thing is I don't want to know how to send a command out and kapture its output for stream 1 and 2 as well as the input, as this is well known to me.
I may explain for what this is needed. You do something and expect not any complications but than you got pages of msg's als err msg or normal output. To be able to see later after it you should be able to get them in a file and as long as you are able to scroll that all back and forther with your mouse it is sure the data is there some where. But the time may be not to scroll and screenshot and scroll ....
I would be glad to help me out in such cases and it would be fine to have the full view including all your own typing and all the msg's in same order as you watch it when you scroll it back.
I don't really know where this is stored and how you could get that saved. I know that I could dump the whole lot of Memory and search it for a part of the xterm window, but that is a bit over the top I think.
There is a control sequence, which I had forgotten. This question reminded me. In XTerm Control Sequences, it is noted "print all pages":
CSI ? Pm i
Media Copy (MC, DEC-specific).
Ps = 1 -> Print line containing cursor.
Ps = 4 -> Turn off autoprint mode.
Ps = 5 -> Turn on autoprint mode.
Ps = 1 0 -> Print composed display, ignores DECPEX.
Ps = 1 1 -> Print all pages.
That dates from 1999 (patch #119), so you likely have it in your xterm. You could do this in a shell command like this:
printf '\033[?11i'
A comment mentions the page Hidden gems of xterm, which uses the corresponding action print-everything (something that can be executed via the translations resource). It is in the manual page, of course. The same comment points to Extra characters in XTerm printerCommand output, which mentions the resource printAttributes. By default, the control sequences for the printer tell xterm to send extra control characters (to reconstruct video attributes). The resource can be modified (set to 0) to suppress that. That is even older (patch #74).
Without that — Conceivably one could construct an application which used the X SendEvent protocol to construct a series of events which would be interpreted as xterm actions to scroll back, select text and copy it chunk-by-chunk via the clipboard. You could even write it in Perl (there is a module for X protocol). But seriously, no.
If you want to capture text which was written to xterm, you can do this by preparing before the text is needed by different methods (see manual):
turn on the xterm logging feature (not that user-friendly because it generates the filename). This can be enabled using the "Log to File (logging)" menu entry.
use the printer control sequences to write lines as they are written (again, not that friendly, though there is a menu entry to turn it on and off, "Redirect to Printer (print-redir)")
use script to capture all output to the terminal. I use this, because it works with any terminal on any POSIX-like system (even Cygwin).
Each of these methods produces a file containing escape/control sequences, which requires filtering out. The hypothetical program using SendEvent could in principle eliminate that.
I wanted to know if there are any resources
available for understanding and using
the 'term' class in urxvt.
The documentation makes a very general
set of references to it, but doesn't really
define the terms.
The uxrvt perl extensions also make very limited use
of the 'term' object, so there isn't much code
to study for reference.
My goals are simple:
To open a new terminal window.
To pass a command to the new terminal window,
then leave the window open for further input.
(example: "ls" or "echo 'Hello World'", then
leave the cursor awaiting further input)
To be able to specify which desktop the
new terminal will appear on.
Questions:
1. How exactly is $term defined?
The documentation says:
$term = new urxvt::term $envhashref, $rxvtname, [arg...]
I've used "my $env = $self->env;" to define the
$envhashref. So I suppose that the existing terminal's
environment variables are used for the new terminal.
I suppose this corresponds directly to the environment
variables themselves, since the following reproduces
those variables...
my #envv = $self->envv;
foreach (#envv) {
print "$_\n";
}
...and the following creates a reference to the 'env' hash:
my $env = $self->env;
Is this correct? It seems odd to have to explicitly declare
the environment if that setting will remain unchanged in the
vast majority of cases.
2. How should $rxvtname be set? Setting it to a name of my
choice results in two windows opening rather than one.
That behavior is odd... what is the correct way to define
the $rxvtname variable?
What exactly does ", [arg...]" refer to?
3. How is $term itself used? It apparently isn't
a reference to the new terminal window. What is its
purpose and how do you use it? An example would
probably be extremely useful here.
4. How can $term->exec_async ($cmd) send a command
to the new terminal window? Is there a better way
to send commands to a new window? Examples?
5. Is there a way to specify which desktop a terminal
window should appear in?
Hopefully this thread can serve as 'documentation' for anyone else
who has already scoured the man pages for urxvt, urxvtperl (as well as
urxvt.pm) and is left without a clear understanding. And if there's
a comprehensive reference on the web somewhere that contains full
explanations and examples, that would be great to know about, too.
Thanks in advance for your help.
I want to extract text contents from GUI apps,here are 2 examples::
example 1:
Suppose I opened firefox, and input url : www.google.com
how can I extract the string "www.google.com" from firefox using my own app ?
example 2:
open calculator(using gcalctool),then input 1+1
How can I extract the string "1+1" of calculator from my own program?
in brief ,what I want is to find out whether there is a way to extract the text contents from any widget of an GUI application
Thanks
I don't think there's a generic way to do this, at least not a very elegant one.
Some inelegant ideas:
You might be able to modify the X window system or even some toolkit framework to extract what is being displayed in specific window elements as text.
You could take a screenshot and use an OCR library to convert the pixels back into text for the interesting areas.
You could recompile the apps of interest to add some kind of mechanism for asking them questions.
You could use something like xtest to inject events highlighting the region of interest and copying it to the clipboard.
I believe firefox and gcalctool are for examples only and you just want to know in general how to pass output of one application to other application.
There are many ways to do that on Linux, like:
piping
application1 | application2
btw here is the Firefox command line manual if you want to start firefox on Ubuntu with a URL. eg:
firefox "$url"
where $url is a variable whose value can be www.mozilla.org
That sounds difficult. Supposing you're running X11, you can very easily grab a window picture ( see "man xwd"); however there is no easy way to get to the text unless it's selected and therefore copied to the clipboard.
Alternatively, if you only want to capture user input, this is quite easy to do, too, by activation the X11 record extension: put this in your /etc/X11/xorg.conf:
Section "Module"
Load "record"
#Load other modules you need ...
EndSection
though it may prove difficult to use too, see example code for Xorg/X11 record extension fails