Wayland session and XWayland configuration at example of KDE - desktop

Dear stackoverflow users,
I am trying to understand how a Wayland session gets invoked at the example KDE to configure XWayland for sandboxing.
The Wayland manual for XWayland is unclear about my sections and neither explains the commands/utils how to handle Wayland/XWayland.
How can I check via command which programs are getting (in future) invoked as Xwayland server?
Are the XWayland configuration files also at /etc/X11/xinit/xinitrc for the client and /etc/X11/xinit/xserverrc for the one global server?
These instructions are abit unlucky without command examples. Does this mean I just need to set $DISPLAY and the Wayland server will start/connect to a xserver?
DISPLAY=":5" application #will this use x11 or Wayland before running it?
kdestart5 starts KDE, but where do I see the configs?
If setting $DISPLAY yourself is possible, does this mean that multiple x11 instances can coexist on the same Wayland session?

To my knowledege, I cant, since the feature is not provided yet. The compositor simply falls back to Xwayland, which may be provide a false sense of security for the user. Retrospectively you can use xeyes.
[correct me, if I am wrong]
Xwayland/Wayland configuration files are not standartized and thus the display manager decides where to put things.
The compositor does handle this. The code is the documentation how/no documentation exists. ls /tmp/.X11-unix/ shows up X0 X1, so X0 is still the xorg display server.
The config is given by sddm --example-config.
The display manager handles the x11 instance, which for simplicity is exactly 1.
All in all there is lacking of documentation and utilities like checking in shell what display an application uses for Wayland and Xwayland.
Common things like using ps auxww | grep X do not work anymore under Wayland.
However even these settings were not reliable on Xorg, which is just painful with respect to availability of XDG_BASE as standard.

Related

Qt application in kiosk mode

I need to start my qt application on desktop under windows and linux in kiosk mode.
May I do it, using qt or special system calls? (not adjusting operation system)
I think you could look into the KDE iosk framework:
http://techbase.kde.org/KDE_System_Administration/Kiosk/Introduction
This is basically written in Qt, and should be working both on Linux and Windows. If you face any troubles, you can at least take their code as a good and robust base.
Here you can find the first paragraph of the introduction inline for your convenience:
The KDE Kiosk is a framework that has been built into KDE since version 3. It allows administrators to create a controlled environment for their users by customizing and locking almost any aspect of the desktop which includes the benign such as setting and fixing the background wallpaper, the functional such as disabling user log outs and access to the print system and the more security conscientious such as disabling access to a command shell.

OS X Associate an extension with the application

In my application, I need to associate an extension with my application programmatically. That is when my application runs, it associates the extensions with itself as preferred application.
On Windows, this is done by using Registry APIs.
I am not able to find out how to achieve this in Mac OS X using Cocoa or Core Foundation in my C++ program.
This is like application associate itself with the extensions.
I assume you want your app to activate when a document with the overtaken extension is double-clicked in Finder, yes? Unfortunately there is no API to "take over" an extension not already declared by the app's Info.plist and, for what should be obvious security reasons, there is no way to modify that mechanism at runtime.
The closest you can come is allowing any extension, which will allow your app to be launched or activated by dragging the document onto the application icon, but I doubt that's all you want to do, given how you phrased your question.

Move Window Linux C

i'd like to make a function that can move a window in Linux in C++ by its PID. So I've tryed in under Windows. But I have trouble to compile it for Linux.
Is there any mean to do it with Qt ? Since I haven't found one, I've tryed to compile for Linux.
I'm using the MoveWindow function, which is part of the Windows API. Is there any Linux equivalent ?
You don't have to do that by hand if you don't really want to as there already are lots of tools out there, that can perform such tasks as moving, resizing, maximizing and whatever windows.
One tool you might want to take a closer look upon goes by the name of wmctrl even if you don't intend to use maybe you'll find some interesting tricks by taking a look into the sources.
The task of moving a window only known by the pid of the client that created the window might not be the easiest tasks of all for a couple of reasons.
First of all you really shouldn't try to do this as in the X Windows philosophy it is the job of the window manager to arrange the windows on the screen.
As well ICCCM (see: http://de.wikipedia.org/wiki/Inter-Client_Communication_Conventions_Manual) as the EWM spec (see: http://standards.freedesktop.org/wm-spec/wm-spec-latest.html) strongly discourage any client from trying to move resize or whatever on its own. Most probably moving windows "owned" by another client might be considered even bigger evil.
The second problem you might face is, that the X 11 protocol doesn't have any notion of pid.
As it was designed to be used over a network you never can't be really sure the program runs on the same machine as the one you are currently sitting in front of. As such there isn't much sense in something like a pid as by chance there might be any number of clients with identical pids displaying windows on the same X Server if they ran on different machines.
Fortunately enough it is not all that bad, as the EWMH spec encourages any client to set the _NET_WM_PID property on its top level window the the pid of the client that created the window.
Again adhering to the EWMH spec isn't enforced by the X Server in any way so that while practically propably almost all clients will set it there's still no guarantee you'll find the window belonging to a specific pid.
Possibilities
While the whole points mentioned until here might seem rather limiting in fact most probably rather the opposite is true. Even because practically it is relatively easy to totally mess up any other client running in an X session the whole set of rules about how to be a good citizen in the X word were introduced.
As the X11 protocol itself is a network protocol (well not 100% true as locally running clients most probably will be communicating with the X Server via a UNIX domain socket) there isn't any specific library required to talk to the X Server.
Talking about C as mentioned in your question the Xlib has long been the one and only one implementation in wide use but there's also another binding called xcb. With a slightly changed API in comparison to the Xlib.
Xlib
Speaking Xlib I've never ever used any xcb until now, so I can't tell you too much about it might be the following methods that might be of use.
XOpenDisplay - open connection to the X server
XQueryTree - aquire the tree of windows currently alive on the server
XInternAtom - no fear it isn't dangerous. Just read about it in the manuals as you'll need it the get the "atom" mapping to _NET_WM_PID mentioned above
XListProperties - search for the _NET_WM_PID property with the value you are looking for
XConfigureWindow, XMoveWindow, XResizeWindow, ... - to finally perform whatever you wish to do.
All functions mentioned above should be documented in the manual pages. Just use man XOpenDisplay for example.
Oh, and be sure to learn about all the other tools at your disposal to further investigate about the X Window world. Run xlsatoms, check what xwininfo reports an take a list at the output of xprop for one single (!) window alone. Try to set some yourself to see what happens xprop will even do that for you if you ask politely.

Is there an API call to disable the network for Linux?

I'm maintaining code on a real-time system running Red Had Enterprise Linux. I'm afraid that sometimes, despite running things at the highest priority, the network manages to slow the computer down, and I would like to disable the card so that I have the full power of the CPU at my disposal. I need some files at the beginning of my function from the network, but after a certain point, I can effectively disable the network until the program is complete. Is there a way I could disable the network through some sort of an API call?
Hopefully someone could expand on this, but it may be worthwhile to look into how ifconfig disables network devices. You probably can do an ioctl on the interface to disable it. Depending on the driver / nic, the kernel may then be able to cause the network hardware to drop packets instead of the cpu.
The source code for ifconfig is here:
http://net-tools.git.sourceforge.net/git/gitweb.cgi?p=net-tools/net-tools;a=blob;f=ifconfig.c;h=be6999578bd81e91e90e26a35fad91f4928f4226;hb=HEAD
Iproute2, which also is able to do the same things as ifconfig is described here:
http://git.kernel.org/?p=linux/kernel/git/shemminger/iproute2.git;a=blob;f=ip/iplink.c;h=6b051b65faab72ea46534ad33f71b3f6cd35c11b;hb=HEAD#l589
I found the source code of iproute2 slightly easier to understand than ifconfig, but it should be relatively easy to see how they interface with the networking stack to disable an interface.
The way the system does it is by issuing ip link set dev ${DEVICE} down 2> null . Looking at the code of ip.c , e.g. here you can check for yourself how it is done. The key is the netif.h that shuts down the network by calling net_if_set_down() . I think it just sets a flag.
netif->flags &= ~NETIF_FLAG_UP
You can go on from here on your own, but keep in mind netif.h is part of the kernel...
The networking is part of the kernel, rather than a user space process. You could do the equivalent of calling rmmod to remove the network driver module from the kernel, assuming you have module support enabled; or you could just set all the netfilter rules to DROP and see if that speeds things up. I'd probably prefer to do that in a launcher script (using the ready-made iptables-save/iptables-restore) rather than coding that in C++. Or you could even just bring the interfaces down.
You said "API" but did not mention the language of your program/script, nor your OS.
On Linux variants like CentOS, RHEL, SuSE, and Fedora, from a bash/Bourne shell script:
/sbin/service network stop
rc=$?
if [ "$rc" -ne 0 ]; then
echo "***** Failed to stop networking service"
exit $rc
fi
# Do your thing
/sbin/service network start

Running a computer in kiosk mode for a custom Linux C++ app

I want to create a C++ application that is to run on some Linux platform on a specific laptop computer. I do however not want the users of this laptop to use any other applications/system features than this program - much like the kiosk modes you would find on computers in a typical internet café.
One issue is that the laptop will be booted by the user, and such has to start my software automatically - leaving as little room as possible for the user to intervene with the process. It does not have to be completely secure, but it should be as close as possible.
What would be the best way to accomplish such a thing? Does there exist (free) Linux distributions specifically made for this (if not, I will probably use Arch Linux)? Are there any steps I could/should take in my program, or can I leave it all to the OS? Would creating my own little Linux distribution specifically for this be worth it?
This shouldn't be on stackoverflow but anyway:
Run a plain X session with no window manager, into this plain X session start your program in fullscreen. Done.
I run a small XUL application this way:
X :10 &
sleep 10
DISPLAY=:10 xulrunner ~/zkfoxtemp/application.ini
I would use a minimal live linux distribution - I prefer tinycorelinux but most will do.
using a minimal distribution ensures that the system doesn't have almost any features or programs you didn't plant there, and will make it easy to modify according to your needs
use a window manager as many programs don't behave properly if ran in plain X session (especially if they use pop up windows), but remove all it's menus and shortcuts
prefer booting from a read only media - this will minimize the chances of corruption (accidentally or intentionally)
remove unneeded services and features from the boot and login scripts