What is the GNOME_TERMINAL_SCREEN environment variable? - gnome

I've recently installed Ubuntu 20.4 LTS on one of my computers. This release of Ubuntu uses the gnome desktop manager (3.36.3) with gnome-terminal (3.36.2) by default.
In each terminal window that I open, the GNOME_TERMINAL_SCREEN environment variable is defined to "/org/gnome/Terminal/screen/some-guid", where each terminal window's GUID is unique.
Does anyone know what this variable is supposed to be used for? Is there some way of using the GUID in Xlib or XCB to identify the terminal's X window?

The $GNOME_TERMINAL_SCREEN environment variable contains an object path for D-Bus.
It is used to address a tab in the Gnome Terminal when starting a process in it, and to be signalled of its termination.
You can see the relevant part of its D-Bus interface by running this command:
dbus-send --session --type=method_call --print-reply \
--dest=org.gnome.Terminal "$GNOME_TERMINAL_SCREEN" \
org.freedesktop.DBus.Introspectable.Introspect
The output (snipped for relevance):
[...]
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.64.6 -->
<node>
[...]
<interface name="org.gnome.Terminal.Terminal0">
<method name="Exec">
<arg type="a{sv}" name="options" direction="in"/>
<arg type="aay" name="arguments" direction="in"/>
</method>
<signal name="ChildExited">
<arg type="i" name="exit_code"/>
</signal>
</interface>
</node>
If you run dbus-monitor and open and close a Gnome Terminal tab, you can see the D-Bus communication in action.
The X Window System is not aware of what goes on in the D-Bus realm, and as far as I know Gnome Terminal does not expose any X specific information through D-Bus.
I have found one way to tie a process to the X window of a Gnome Terminal in which it is running, but it is less than ideal. Nonetheless, it may suffice for your purposes.
The idea as that when opening a Gnome Terminal window, we will generate an identifying value, and store it both in an X property of the Gnome Terminal window, and in an environment variable.
We can then later get the environment variable from the environment of the process (via /proc/<pid>/environ if needed), and scan the windows for the one which has our value in the X property.
As the window does not exist yet when opening a new Gnome Terminal, we can not set a property ourselves, but the gnome-terminal command accepts an option --role, and stores its value in the WM_WINDOW_ROLE X property of the Gnome Terminal window.
The purpose of the WM_WINDOW_ROLE X property is to uniquely identify windows belonging to the same client.
Without --role, Gnome Terminal assigns it a unique value, but you can do this yourself.
So here is a start-gnome-terminal wrapper, which you could invoke from the key binding which would normally start gnome-terminal:
#!/bin/sh
FINDWIN_ROLE=findwin-role-$(xxd -p -l 16 < /dev/urandom)
export FINDWIN_ROLE
exec gnome-terminal --role "$FINDWIN_ROLE" "$#"
To look through the windows for the property later, you could use wmctrl -l and xprop.

Related

How to adjust the log output level of GTK4?

When developing an application based on GTK4, a log will be printed every time it is started. How can I get rid of it?
(conquerdocker:17460): Gtk-WARNING **: 09:13:21.962: Unknown key gtk-button-images in /home/aszswaz/.config/gtk-4.0/settings.ini
(conquerdocker:17460): Gtk-WARNING **: 09:13:21.962: Unknown key gtk-menu-images in /home/aszswaz/.config/gtk-4.0/settings.ini
(conquerdocker:17460): Gtk-WARNING **: 09:13:21.963: Unknown key gtk-toolbar-style in /home/aszswaz/.config/gtk-4.0/settings.ini
If you are not concerned about having any log output when you are executing your program, you could call your program and redirect the logging output to "/dev/null", such as:
./your_program_name > /dev/null
Alternatively, since your program is most likely a GUI program and doesn't require a terminal/console window, you could set up a desktop file similar to the following example.
[Desktop Entry]
Type=Application
Name=GtkProgramName
Icon=/home/username/.local/share/icons/hicolor/48x48/apps/GTK.png
Categories=Utilities;
StartupNotify=true
Terminal=false
Exec=/path/to/your/Programs/your_program_name
The key attribute here is the "Terminal=false" attribute which will run your program without a terminal, and therefore a user would not see spurious messages. Desktop files usually are placed in the "~/.local/share/applications folder" and have a permission mask of "rw-rw-r--".
You might give those options a try.
Regards.

Trying to create a handler for .maff files in Linux

MAFF files are simply zip files. I'm trying to create a handler for .maff in linux so that when I click on them or type xdg-open x.maff it will call my handler instead of the default which is to open the directory in nautilus. I created an application-x-maff.xml file that contains:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-maff">
<comment>maff type</comment>
<magic priority="100">
<match offset="0" type="string" value="PK\x03\x04" />
</magic>
<glob pattern="*.maff"/>
</mime-type>
</mime-info>
and saved in ~/.local/share/mime/packages. Created also a ~/.local/share/applications/maffapplication.desktop that contains
[Desktop Entry]
Type=Application
MimeType=application/x-maff
Name=Maff Handler
Exec=<my home path>/bin/linux/maffHandler
and executed
% update-mime-database ~/.local/share/mime/packages/
% update-desktop-database ~/.local/share/applications
If I do
% gio info x.maff (filtered)
standard::content-type: application/x-maff
standard::fast-content-type: application/x-maff
and if I do
% gio mime application/x-maff
Registered applications:
maffapplication.desktop
Recommended applications:
maffapplication.desktop
everything seems to be right ... but then xdg-open x.maff does not work, still calls nautilus ... worse yet, if I do
% xdg-mime query filetype x.maff
application/zip
I'm sure I'm missing something ... somehow I need to override this association between the .maff file that starts with the same magic as a zip file to no avail ... I tried all kinds of modifications on the xml file, with and without the magic, nothing works
By the way, if I do
% maffHandler x.maff
it works perfectly and opens the maff file in firefox, I'm willing to share the C++ code of that if anyone is interested
Seems that TDE (Trinity Desktop) does not properly set two important environment variables
setenv XDG_CURRENT_DESKTOP KDE
setenv KDE_SESSION_VERSION 5
Once they are set at .login (unfortunately had to log out and login again) xdg- scripts started working properly and recognizing the MIME types. The other problem is that TDE requires that you manually add the association on Control Center -> TDE Components -> File Associations.
After environment variables properly set for my environment and File Associations set, then it all works perfectly. Thanks

Remote creation of Custom actions in Thunar

I'm using Thunar as file browser for a linux network composed of 100 CentOS 7.2 machines. We are managing the installation of those workstations with a PXE server and SaltStack installation.
I need to create those custom actions during the installation.
Currently, Thunar is installed on every workstations, the script is available on a share but I need to create the custom action on each machine. Open Thunar, Edit > Create custom actions and it launches my script in xterm for the selected folder:
xterm -e "/path/to/my/script.sh %f"
Is there a way to create Thunar's custom actions from command lines or by editing a file so that I will be able to launch them through Salt cmd.run?
Thanks for your help.
I've found out that those Custom actions are store in this file:
cat ~/.config/Thunar/uca.xml
Here is an example of the syntaxe:
<?xml encoding="UTF-8" version="1.0"?>
<actions>
<action>
<icon>script.png</icon>
<name>My custom action</name>
<unique-id>1479309009025049-2</unique-id>
<command>xterm -e "/path/to/my/script.sh %f"</command>
<patterns>*</patterns>
<startup-notify/>
<directories/>
<audio-files/>
<image-files/>
<other-files/>
<text-files/>
<video-files/>
</action>
</actions>
That way, I can create this template file and copy it in the user folder.

QEMU simple backend tracing dosen't print anything

I'm doing get simple trace file from QEMU.
I followed instructions docs/tracing.txt
with this command "qemu-system-x86_64 -m 2G -trace events=/tmp/events ../qemu/test.img"
i'd like to get just simple trace file.
i've got trace-pid file, however, it dosen't have anything in it.
Build with the 'simple' trace backend:
./configure --enable-trace-backends=simple
make
Create a file with the events you want to trace:
echo bdrv_aio_readv > /tmp/events
echo bdrv_aio_writev >> /tmp/events
Run the virtual machine to produce a trace file:
qemu -trace events=/tmp/events ... # your normal QEMU invocation
Pretty-print the binary trace file:
./scripts/simpletrace.py trace-events trace-* # Override * with QEMU
i followd this instructions.
please somebody give me some advise for this situation.
THANKS!
I got same problem by following the same document.
https://fossies.org/linux/qemu/docs/tracing.txt
got nothing because
bdrv_aio_readv and bdrv_aio_writev was not enabled by default, at least the version I complied, was not enabled. you need to open trace-events under source directory, looking for some line without disabled, e.g. I using:
echo "load_file" > /tmp/events
Then start qemu,
after a guest started, I run
./scripts/simpletrace.py trace-events trace-Pid
I got
load_file 1474.156 pid=5249 name=kvmvapic.bin path=qemu-2.8.0-rc0/pc-bios/kvmvapic.bin
load_file 22437.571 pid=5249 name=vgabios-stdvga.bin path=qemu-2.8.0-rc0/pc-bios/vgabios-stdvga.bin
load_file 10034.465 pid=5249 name=efi-e1000.rom
you can also add -monitor stdio to qemu command line, after it started, you can the following command in qemu CLI:
(qemu) info trace-events
load_file : state 1
vm_state_notify : state 1
balloon_event : state 0
cpu_out : state 0
cpu_in : state 0
1 means enabled events.
Modify the trace-events file in the source tree
As of v2.9.0 you also have to remove the disable from the lines you want to enable there, e.g.:
-disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
+exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
and recompile.
Here is a minimal fully automated runnable example that boots Linux and produces traces: https://github.com/cirosantilli/linux-kernel-module-cheat
For example, I used the traces to count how many boot instructions Linux has: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/c7bbc6029af7f4fab0a23a380d1607df0b2a3701/count-boot-instructions.md
I have a lightly patched QEMU as a submodule, the key commit is: https://github.com/cirosantilli/qemu/commit/e583d175e4cdfb12b4812a259e45c679743b32ad

Replacing Gnomes virtual keyboard with Onboard -> Hide/Show via DBus doesn't work

I'm using Gnome on a tablet as a daily driver. The integrated virtual keyboard doesn't serve as a replacement for a real keyboard, but I need exactly that. Thus I want to replace it with Onboard, and started to write an extension for Gnome Shell. The goal is to hide and show Onboard when the integrated virtual keyboard would be hidden/shown.
I can show/hide Onboard through DBus like this:
dbus-send --type=method_call --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.Show
I adapted the example at https://wiki.gnome.org/Gjs/Examples/DBusClient to test showing/hiding Onboard through DBus:
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
// This the D-Bus interface as XML
const OnboardInterface = '<node> \
<interface name="org.onboard.Onboard.Keyboard"> \
<method name="ToggleVisible"> \
</method> \
<method name="Show"> \
</method> \
<method name="Hide"> \
</method> \
</interface> \
</node>';
// Declare the proxy class based on the interface
const OnboardProxy = Gio.DBusProxy.makeProxyWrapper(OnboardInterface);
let OnbProxy = new OnboardProxy(
Gio.DBus.system,
"org.onboard.Onboard",
"/org/onboard/Onboard/Keyboard"
);
OnbProxy.ShowSync()
let loop = new GLib.MainLoop(null, false);
loop.run();
Sadly it doesn't show Onboard, instead throws this error:
$ gjs ./test.js
(gjs:13144): Gjs-WARNING **: JS ERROR: Gio.DBusError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.onboard.Onboard was not provided by any .service files
_proxyInvoker#resource:///org/gnome/gjs/modules/overrides/Gio.js:98
_makeProxyMethod/<#resource:///org/gnome/gjs/modules/overrides/Gio.js:124
#./test.js:26
JS_EvaluateScript() failed
I have no clue why it talks about services when all I wan't to do is sending a message trough DBus? It's probably a rather stupid mistake as I don't have any experience with either Gnome Shell extensions nor DBus..
Version of Gnome is 3.18.0
Found the solution: replace Gio.DBus.system with Gio.DBus.session
Onboard isn't a system service but started in the users session, thus it didn't work.
The extenstion will be available on https://extensions.gnome.org/ as soon as it's verified, just search for "Onboard integration". And I did another related one as well, "Slide for keyboard" does what it says (slide from the bottom)

Resources