How to show and hide the on-screen keyboard "onboard" in mate-screensaver? - c

I'm trying to add a mate-screensaver, so that there would be a switch on and off the on-screen keyboard (onboard) right on the window. All the functionality is ready, I use 2 settings of the org.mate.screensaver schemas:
embedded-keyboard-enabled
embedded-keyboard-command "onboard --xid"
When switching the switch, I change the value of embedded-keyboard-enabled to true or false, respectively, but the keyboard appears or disappears only after restarting the mate-sreensaver window. As I understand it, the keyboard is created by an asynchronous process, but how do I hide or show it when I need it?
Of the functions, I use g_settings_set_boolean() to set the key parameter and g_settings_apply() to apply the changes.

I wrote a little script that I load at login which toggles hide and show using my middle mouse button. This works very when I want to hide/show it quickly.
You could copy and past the below script, give it execution permission, and run it at startup. (You may need to install xprintidle.)
Copy and paste below text in your favourite text editor.
#!/usr/bin/bash
if [[ "$(pidof -x $(basename $0))" != $$ ]] ; then exit;fi
rest=0
sleep 35;# (i need to wait 30-35 seconds at login for the physical mouse id to be assigned instead of the virtual mouse. It might go quicker for you.)
MOUSE=$(xinput --list --long | grep XIButtonClass | head -n 1 | egrep -o '[0-9]+');
toggle() { dbus-send --type=method_call --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.ToggleVisible;
}
while :;do
idle3=$(xprintidle)
STATE=$(xinput --query-state $MOUSE);
if [[ $STATE == *"button[2]=down"* ]];then toggle;sleep .5;elif [ $idle3 -gt 3000 ] && [ $rest = '.14' ];then rest=3;else rest=.14;fi;
sleep $rest;
done

Related

pyqgis plugin change QDialog to QMainWindow

I have a plugin window is QDialog, but I want to add QMenubar or QStatusBar
I have tried to find a way to convert QDialog to QMainWindow, but there is no result,
So I try to add QMenubar in QDialog again and everything works fine
Until the position of the object I added to the layout screen ran to the upper left corner.
I am not a native English speaker
def run(self):
"""Run method that performs all the real work"""
# Create the dialog with elements (after translation) and keep reference
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start == True:
self.first_start = False
#建立menuBar的父節點物件
file_menu = QMenu("File")
#建立一個
open_action = QAction("Open",file_menu)
open_action.setShortcut('Alt+F4')
#把剛才建立的open action 加入file 節點
file_menu.addAction(open_action)
#建立一個menubar物件
menubar = QMenuBar(self.dlg)
#將父節點加入menubar
menubar.addMenu(file_menu)
#將self.dlg的menubar設定為menubar物件
self.dlg.setMenuBar(menubar)
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result:
# Do something useful here - delete the line containing pass and
# substitute with your code.
pass

How can I get updated system DPI information from X11 in a C program?

I'm trying to create a DPI aware app which responds to user requested DPI change events by resizing the window.
The program in question is created in C and uses SDL2, however to retrieve system DPI information I use xlib directly, as the SDL DPI support in X11 is lacking.
I found two ways to get the correct DPI information on program startup, both involving getting Xft.dpi information from Xresource: one is to use XGetDefault(display, "Xft", "dpi"), while the other is to use XResourceManagerString, XrmGetStringDatabase and XrmGetResource. Both of them return the correct DPI value when the program is created.
The problem is, if the user changes the system scale while the program is running, both XGetDefault abd XrmGetResource still return the old DPI value even though when I run "xrdb -query | grep Xft.dpi" the value has indeed changed.
Does anyone know a way to get the updated Xft.dpi value?
I found out a way to do exactly what I wanted, even though it's rather hackish.
The solution (using XLib) is to create a new, temporary connection to the X server using XOpenDisplay and XCloseDisplay, and poll the resource information from that new connection.
The reason this is needed is because X fetches the resource information only once per new connection, and never updates it. Therefore, by opening a new connection, X will get the updated xresource data, which can then be used for the old main connection.
Be mindful that constantly opening and closing new X connections may not be great for performance, so only do it when you absolutely need to. In my case, since the window has borders, I only check for DPI changes when the title height has changed, as a DPI change will change the size of your title border due to font size differences.
First off it must be noted that the value of the Xft.dpi resource isn't necessarily accurate -- it depends on whether the system and or user login scripts have correctly set it or not.
Also it is important to remember that the Xft.dpi resource is intended to be used by the Xft library, not by arbitrary programs looking for the screen resolution.
The Xft.dpi resource can be set as follows. This example effectively only deals with a display with a single screen, and note that it uses xdpyinfo. This also shows how it might not be exact, but could be rounded. Finally this example shows calculation of both the horizontal and vertical resolution, but Xft really only wants the horizontal resolution:
SCREENDPI=$(xdpyinfo | sed -n 's/^[ ]*resolution:[ ]*\([^ ][^ ]*\) .*$/\1/p;//q')
SCREENDPI_X=$(expr "$SCREENDPI" : '\([0-9]*\)x')
SCREENDPI_Y=$(expr "$SCREENDPI" : '[0-9]*x\([0-9]*\)')
# N.B.: If true screen resolution is within 10% of 100DPI it makes the most
# sense to claim 100DPI to avoid font-scaling artifacts for bitmap fonts.
if expr \( $SCREENDPI_X / 100 = 1 \) \& \( $SCREENDPI_X % 100 \<= 10 \) >/dev/null; then
FontXDPI=100
fi
if expr \( $SCREENDPI_Y / 100 = 1 \) \& \( $SCREENDPI_Y % 100 \<= 10 \) >/dev/null; then
FontYDPI=100
fi
echo "Xft.dpi: ${FontYDPI}" | xrdb -merge
I really wish I knew why Xft didn't at least try to find out the screen's resolution itself instead of relying all of the time on its "dpi" resource being set, but I've found that the current implementation only uses the resource setting, so something like the above is actually always necessary to set the resource properly (and further one must also make sure the X Server itself has been properly configured with the correct physical screen dimensions).
From a C program you want to do just what xdpyinfo itself does and skip all the nonsense about Xft's resources. Here's the xdpyinfo code paraphrased:
Display *dpy;
dpy = XOpenDisplay(displayname);
for (scr = 0; scr < ScreenCount(dpy); scr++) {
int xres, yres;
/*
* there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
*
* dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
* = N pixels / (M inch / 25.4)
* = N * 25.4 pixels / M inch
*/
xres = ((((double) DisplayWidth(dpy, scr)) * 25.4) /
((double) DisplayWidthMM(dpy, scr))) + 0.5;
yres = ((((double) DisplayHeight(dpy, scr)) * 25.4) /
((double) DisplayHeightMM(dpy, scr))) + 0.5;
}
XCloseDisplay(dpy);
Note also that if you are for some odd reason scaling your whole display (e.g. with xrandr), then you should want the fonts to scale equally with everything else. It's just a horrible bad hack to use whole-screen scaling to scale just the fonts, especially when for most things it's simpler to just tell the application to use properly scaled fonts that will display at a constant on-screen point size (which is exactly what Xft uses the "dpi" resource to do). I'm guessing Ubuntu does something stupid to change the screen resolution, e.g. using xrandr to scale up the apparent size of icons and other on-screen widgets without applications having to know about screen size and resolution, then it has to lie to Xft by rewriting the Xft.dpi resource.
Note that if you avoid whole-screen scaling then applications that don't use Xft can still get proper font scaling by correctly requesting a properly scaled font, i.e. even with bitmap fonts you can get them scaled to the proper physical on-screen size by using the screen's actual resolution in the font-spec. E.g. continuing from the above shell fragment:
# For pre-Xft applications we can specify physical font text sizes IFF we also tell
# it the screen's actual resolution when requesting a font. Note the use of the
# rounded values here.
#
DecentDeciPt="80"
DecentPt="8"
export DecentDeciPt DecentPt
#
# Best is to arrange one's font-path to get the desired one first, but....
# If you know the name of a font family that you like and you can be sure
# it is installed and in the font-path somewhere....
#
DefaultFontSpec='-*-liberation mono-medium-r-*-*-*-${DecentDeciPt}-${FontXDPI}-${FontYDPI}-m-*-iso10646-1'
export DefaultFontSpec
#
# For Xft we have set the Xft.dpi resource so this allows the physical font size to
# be specified (e.g. with Xterm's "-fs" option) and for a decent scalable font
# to be chosen:
#
DefaultFTFontSpec="-*-*-medium-r-*-*-*-*-0-0-m-*-iso10646-1"
DefaultFTFontSpecL1="-*-*-medium-r-*-*-*-*-0-0-m-*-iso8859-1"
export DefaultFTFontSpec DefaultFTFontSpecL1
# Set a default font that should work for everything
#
eval echo "*font: ${DefaultFontSpec}" | xrdb -merge
Finally here's an example of starting an xterm (that's been compiled to use Xft) with the above settings (i.e. the Xft.dpi resource and the shell variables above) to show text at physical size of 10.0 Points on the screen:
xterm -fs 10 -fa $DefaultFTFontSpec
You could try to use xdpyinfo(1); on my system it outputs, among a lot of other things:
dimensions: 1280x1024 pixels (332x250 millimeters)
resolution: 98x104 dots per inch
depths (7): 24, 1, 4, 8, 15, 16, 32
I don't know whether it can help you because I don't know how do you change the DPI of your screen, but chances are it works. Good luck!
--- UPDATE after comment ---
In a comment below from the OP, it is said that "there is a setting to change the DPI"... still I don't know which. Anyway, I tried Ctrl+Alt+Plus and Ctrl+Alt+Minus to change the resolution of the X server on the fly. After having changed the resolution, and seeing everything bigger than before, I ran xdpyinfo again. IT DIDN'T WORK: still the same output. But may be the method you use (which?) instead works...

Powershell GUI & loop pauses

What I want: my script/program(?) To do stuff on button press then wait if conditions are meet and display how long is left.
Whats happening: When I use 'Start-Sleep' it pauses the GUI and doesn't display how long is left until the very end when it displays all of the text at once.
I've attempted to look for something online and came up dry. I've attempted for, while, and do-until loops all act the same way. So I'm hoping there is another way to pause a loop.
This is basically the script I'm using:
$btn.add_click ({
Foreach ($_ in $stuff)
{
#do stuff
If ($x -eq $y)
{
$n = 30
While ($n -gt 0)
{
$textbox.text += "$n seconds left`n"
###WAIT 1-5 SECOND(s)###
$n --
}
}
}
})
Here is a very comprehensive tutorial by #FoxDeploy that helps you build your WPF GUI in a way that allows commands to be triggered from the UI without freezing it.
I don't share any code here because there is really too much of it.

In AutoIt, WinWait still waits after the window has opened

I used AU3info to make sure I am using the right windows title.
RunWait ("\\sv44\vol1\Install\LibreOffice\install /exenoui")
WinWait("Installation of LibreOffice")
Send("{ENTER}")
What I am trying to achieve: When I the confirmation box appears ("Installation of LibreOffice"), press OK.
WinWait loops forever. I tried WinWaitActive...same result.
How do I make it work?
When manipulating external application windows, always use #RequireAdmin in order to get a permission elevation. Also use Opt("WinSearchChildren", 1) in order to search child windows too. Play with "WinTitleMatchMode".
#RequireAdmin ; Will give your script a permission elevation (sometimes its needed)
Opt("WinTitleMatchMode", 2) ; 1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Opt("WinSearchChildren", 1) ; 0=no, 1=search children also
RunWait("\\sv44\vol1\Install\LibreOffice\install /exenoui")
WinWait("Installation of LibreOffic")
Send("{ENTER}")
Notice that I use "Installation of LibreOffic" (missing "e") because Opt is set to use substring and not the whole title (just in case).

Maya MEL command to set focus to a particular tab in the Attribute Editor

How can I do this? I've looked through the Maya documentation and all I can see that's related are the commands refreshAE and updateAE, but they don't do the job I need.
Here is one way of doing it. This proc is tested in Maya 2009 and 2013.
// switch the tab by name string, note tab must be present
global proc switchAEtoTab(string $name ){
global string $gAETabLayoutName;
string $tabs[] = `tabLayout -q -tabLabelIndex $gAETabLayoutName`;
for ($i=0;$i<size($tabs);$i++){
if ($tabs[$i]==$name)
tabLayout -e -selectTabIndex ($i+1) $gAETabLayoutName;
}
}
Edit: updated script to contain the global name of the tab layout

Resources