x11 interview questions
Top x11 frequently asked interview questions
How can you run GUI apps in a docker container?
Are there any images that set up vncserver
or something so that you can - for example - add an extra speedbump sandbox around say Firefox?
Source: (StackOverflow)
I've installed Octave and gnuplot via Homebrew, and downloaded AquaTerm.dmg.
When I try to plot, I get the following message:
octave:4> plot(x,y)
gnuplot> set terminal aqua enhanced title "Figure 1" font "*,6"
^
`line 0: unknown or ambiguous terminal type; type just 'set terminal' for a list`
In a bash terminal set terminal
, set Terminal
, set term
, (and the same, followed by "aqua" too) etc gives nothing.
I've tried plotting again from octave having the "AquaTerm" already open, but nothing. I've tried plotting directly from gnuplot but same problem.. How can I do this "set terminal aqua"?
Gnuplot starting message says "Terminal type set to 'x11'
" but no idea how to change it, the previous commands didn't work neither.
Since AquaTerm wasn't installed from Homebrew maybe octave/gnupot can't find it... but no idea.
Any guess? Thanks!
Source: (StackOverflow)
I have box where I run tests. It seems like Jenkins would ssh in and execute commands described in the specific job that's running.
Here I am trying to run my Selenium Webdriver tests, but it tells me that I have errors in launching firefox. The end idea is to run the webtests on this box entirely, and also take some screenshots of errors.
I am using selenium-java-2.25.jar, firefox 10, linux OS.
The funny thing is that I can ssh in manually into the box, temporarily copy the magic cookie from another user on the box (to get an X tunnel), do an export DISPLAY=mydisplay:1.0
, then launch my selenium tests using ant. And this will bring up firefox and the tests just fine.
There are various threads here that seem to have the exact same problem, and I think I've tried most of them. Here is what I've done:
Reboot the box, log back in with VNC.
Placed a bash script in Jenkins to run before running selenium tests. The bash script basically just does an export DISPLAY=mydisplay:1.0
. It also executes xclock
. This works as I can see xclock being displayed in the VNC.
iptables have been turned off
firefox is correctly located in /usr/bin/firefox
sshd_config shows having X11Forwarding as true.
Supposedly downgrading firefox helped some people, but I do not wish to do this. Webdriver should support FF 10 anyway.
However, none of the above solves the problem.
It doesn't seem like port 7055 on localhost even exists:
netstat -an | grep 7055
- Nothing prints
This is what my /etc/hosts says:
1 127.0.0.1 localhost.localdomain localhost
2 ::1 localhost6.localdomain6 localhost6
Perhaps it has something to do with localhost:7055 not existing? I am unsure where to go from here. still, why does the error output say it's looking for display: :0.0
when I've specified mydisplay:1.0
?
And finally the error output I receive:
[testng] org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng]
[testng] Error: cannot open display: :0.0
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng]
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng]
[testng] Xlib: connection to ":0.0" refused by server
[testng] Xlib: No protocol specified
[testng]
[testng] Error: cannot open display: :0.0
[testng]
[testng] at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:109)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:245)
[testng] at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:109)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:185)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:174)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
[testng] at com.test.webtest.browser.BrowserFactory.createBrowser(BrowserFactory.java:24)
[testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[testng] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[testng] at java.lang.reflect.Method.invoke(Method.java:601)
Source: (StackOverflow)
I'm trying to create a small window manager (just for fun), but I'm having problems in handling windows created by Firefox (only with that application, other apps works fine)
The problem is, after I launch Firefox, and add my decoration, it seems to work fine, but if for example I try to click on the menu button, the (sub)window doesn't appear.
What seems to happen is that after the click, a ClientMessage event is fired with the following values:
Data: (null)
Data: _NET_WM_STATE_HIDDEN
Data: (null)
Data: (null)
Data: (null)
Now the problem is that I don't know how to show the window, which window.
I tried with:
- XRaiseWindow
- XMapWindow
- I tried to get the transient window and show it
But without success. What I don't understand is that if this client message is generated by the menu subwindow or not.
How should I show a window that is in _NET_WM_STATE_HIDDEN?
Another strange problem is that after receiving the ClientMessage, I always receive 2 UnMapNotify Events.
I also have another question, if I want to show the "File, Edit" menù (in Firefox it appears, if I remember correctly, when you press the Alt button.
Maybe Firefox creates a tree of windows?
This is the loop where I handle the events:
while(1){
XNextEvent(display, &local_event);
switch(local_event.type){
case ConfigureNotify:
configure_notify_handler(local_event, display);
break;
case MotionNotify:
motion_handler(local_event, display);
break;
case CreateNotify:
cur_win = local_event.xcreatewindow.window;
char *window_name;
XFetchName(display, cur_win, &window_name);
printf("Window name: %s\n", window_name);
if(window_name!=NULL){
if(!strcmp(window_name, "Parent")){
printf("Adding borders\n");
XSetWindowBorderWidth(display, cur_win, BORDER_WIDTH);
}
XFree(window_name);
}
break;
case MapNotify:
map_notify_handler(local_event,display, infos);
break;
case UnmapNotify:
printf("UnMapNotify\n");
break;
case DestroyNotify:
printf("Destroy Event\n");
destroy_notify_handler(local_event,display);
break;
case ButtonPress:
printf("Event button pressed\n");
button_handler(local_event, display, infos);
break;
case KeyPress:
printf("Keyboard key pressed\n");
keyboard_handler(local_event, display);
break;
case ClientMessage:
printf("------------ClientMessage\n");
printf("\tMessage: %s\n", XGetAtomName(display,local_event.xclient.message_type));
printf("\tFormat: %d\n", local_event.xclient.format);
Atom *atoms = (Atom *)local_event.xclient.data.l;
int i =0;
for(i=0; i<=5; i++){
printf("\t\tData %d: %s\n", i, XGetAtomName(display, atoms[i]));
}
int nchild;
Window *child_windows;
Window parent_window;
Window root_window;
XQueryTree(display, local_event.xclient.window, &root_window, &parent_window, &child_windows, &nchild);
printf("\tNumber of childs: %d\n", nchild);
break;
}
Now in the clientmessage actually I'm just trying to see collect some information to understand what is happening. And what I can see from the code above, is that the window that raised the event contains one child (again: is that the menu? or not?)
The code for the MapNotify event, where I add the decoration is the following:
void map_notify_handler(XEvent local_event, Display* display, ScreenInfos infos){
printf("----------Map Notify\n");
XWindowAttributes win_attr;
char *child_name;
XGetWindowAttributes(display, local_event.xmap.window, &win_attr);
XFetchName(display, local_event.xmap.window, &child_name);
printf("\tAttributes: W: %d - H: %d - Name: %s - ID %lu\n", win_attr.width, win_attr.height, child_name, local_event.xmap.window);
Window trans = None;
XGetTransientForHint(display, local_event.xmap.window, &trans);
printf("\tIs transient: %ld\n", trans);
if(child_name!=NULL){
if(strcmp(child_name, "Parent") && local_event.xmap.override_redirect == False){
Window new_win = draw_window_with_name(display, RootWindow(display, infos.screen_num), "Parent", infos.screen_num,
win_attr.x, win_attr.y, win_attr.width, win_attr.height+DECORATION_HEIGHT, 0,
BlackPixel(display, infos.screen_num));
XMapWindow(display, new_win);
XReparentWindow(display,local_event.xmap.window, new_win,0, DECORATION_HEIGHT);
set_window_item(local_event.xmap.window, new_win);
XSelectInput(display, local_event.xmap.window, StructureNotifyMask);
printf("\tParent window id: %lu\n", new_win);
put_text(display, new_win, child_name, "9x15", 10, 10, BlackPixel(display,infos.screen_num), WhitePixel(display, infos.screen_num));
}
}
XFree(child_name);
}
Now can someone help me with these problems? Unfortunately I already googled many times, but without success.
To sum up, my issues are two:
1. How to show subwindows from Firefox
2. How to show the File, Edit menu.
UPDATE
I noticed something strange testing Firefox with xev to understand what events are fired in order to show an application. I saw that using Firefox in unity, and using Firefox in another window manger, the events fired are completely different. In Unity I have only:
- ClientMessage
- UnmapNotify
Instead using Firefox, for example with xfce4, the xevents generated are more:
- VisiblityNotify (more than one)
- Expose event (more than one)
But if I try to enable VisibilityChangeMask in my wm, I receive the following events:
- ConfigureNotify
- ClientMessage
- MapNotify
- 2 UnMapNotify
UPDATE 2
I tried to read the XWMhints properties in the ClientMessage window (probably the menù window) and the values are:
For the flags 67 = InputHint, StateHint, WIndowGroupHint
For the initial state NormalState
UPDATE 3
I tried to look how another window manager works, and I was looking at the source code of calmwm. What is my understanding is that, when the ClientMessage event arrives, with a _NET_WM_STATE message, it updates these properties, and in the case of _NET_WM_STATE_HIDDEN it clears this property, and the result will be that the property will be deleted. So I tried to update my code to delete that property, but it's still not working. Anyway the relevant updated code in client_message_handler now looks like this:
Atom *atoms = (Atom *)local_event.xclient.data.l;
int i =0;
for(i=0; i<=5; i++){
printf("\t\tData %d: %s\n", i, XGetAtomName(display, atoms[i]));
if(i==1){
printf("\t Deleting Property: _NET_WM_STATE_HIDDEN \n");
XDeleteProperty(display, cur_window, atoms[i]);
}
}
It is only a test, and I'm sure that i=1 in my case is the _NET_WM_STATE_HIDDEN property.
Here a link to calmwm source code: https://github.com/chneukirchen/cwm/blob/linux/xevents.c
So I'm still stuck at that point.
UPDATE 4
Really I don't know if it helps, but I tried to read the window attributes in the MapNotify Event, and the window map_state is IsViewable (2).
UPDATE 5
I found a similar problem here in SO, using xlib with python: Xlib python: cannot map firefox menus
The solution suggests to use XSetInputFocus, i tried that on my XMapNotify handler:
XSetInputFocus(display, local_event.xmap.window, RevertToParent, CurrentTime);
But it still doesn't help, the firefox menu still doesn't appear!!
And i have the same problem with right-click.
UPDATE 6
Playing with xconfigurenotify event and unmap event i found that the:
Xconfigure request has 2 window fields: window and above, and when the
the xconfigurerequest.window value is the same of xunmap.window value.
And also that the xconfigurerequest.above is always changing, but xconfigurerequest.window is always the same in all events.
It seems that the xconfigurerequest.above is related to what menu i'm trying to open. For example:
- if right-click on a page i get an id (always the same for every subsequent click)
- if i right-clik on a tab, the above value is another one
- and the same happen if i left-click the firefox main menu
Still don't know if that helps.
Really don't know
Anyone got any idea?
Source: (StackOverflow)
One of my new home projects will be a simple Window Manager, but before start I need to know some things:
- Which is the best language to do this?
- Where to get some resources to learn?
Source: (StackOverflow)
When I run some programs over SSH, such as firefox &
, I get an error
Error: no display specified
I would like open many displays, still showing the stdout
of each program.
Initial Question: How can I can specify the display to get a many-displayed program?
Pablo Santa Cruz gives me the following code as a solution.
I do not understand it.
$ export DISPLAY=yourmachine.yourdomain.com:0.0
$ firefox &
What are yourmachine
and yourdomain.com
in the command?
Source: (StackOverflow)
Under Linux, my C++ application is using fork() and execv() to launch multiple instances of OpenOffice so as to view some powerpoint slide shows. This part works.
Next I want to be able to move the OpenOffice windows to specific locations on the display. I can do that with the XMoveResizeWindow() function but I need to find the Window for each instance.
I have the process ID of each instance, how can I find the X11 Window from that ?
UPDATE - Thanks to Andy's suggestion, I have pulled this off. I'm posting the code here to share it with the Stack Overflow community.
Unfortunately Open Office does not seem to set the _NET_WM_PID property so this doesn't ultimately solve my problem but it does answer the question.
// Attempt to identify a window by name or attribute.
// by Adam Pierce <adam@doctort.org>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <iostream>
#include <list>
using namespace std;
class WindowsMatchingPid
{
public:
WindowsMatchingPid(Display *display, Window wRoot, unsigned long pid)
: _display(display)
, _pid(pid)
{
// Get the PID property atom.
_atomPID = XInternAtom(display, "_NET_WM_PID", True);
if(_atomPID == None)
{
cout << "No such atom" << endl;
return;
}
search(wRoot);
}
const list<Window> &result() const { return _result; }
private:
unsigned long _pid;
Atom _atomPID;
Display *_display;
list<Window> _result;
void search(Window w)
{
// Get the PID for the current Window.
Atom type;
int format;
unsigned long nItems;
unsigned long bytesAfter;
unsigned char *propPID = 0;
if(Success == XGetWindowProperty(_display, w, _atomPID, 0, 1, False, XA_CARDINAL,
&type, &format, &nItems, &bytesAfter, &propPID))
{
if(propPID != 0)
{
// If the PID matches, add this window to the result set.
if(_pid == *((unsigned long *)propPID))
_result.push_back(w);
XFree(propPID);
}
}
// Recurse into child windows.
Window wRoot;
Window wParent;
Window *wChild;
unsigned nChildren;
if(0 != XQueryTree(_display, w, &wRoot, &wParent, &wChild, &nChildren))
{
for(unsigned i = 0; i < nChildren; i++)
search(wChild[i]);
}
}
};
int main(int argc, char **argv)
{
if(argc < 2)
return 1;
int pid = atoi(argv[1]);
cout << "Searching for windows associated with PID " << pid << endl;
// Start with the root window.
Display *display = XOpenDisplay(0);
WindowsMatchingPid match(display, XDefaultRootWindow(display), pid);
// Print the result.
const list<Window> &result = match.result();
for(list<Window>::const_iterator it = result.begin(); it != result.end(); it++)
cout << "Window #" << (unsigned long)(*it) << endl;
return 0;
}
Source: (StackOverflow)
I am trying to install a program (a Java application) on my Linux machine (I am using Slackware). I have received the following error, and I do not understand it. Could you advise me how to approach the problem? I am not sure whether this is a kind of question I could ask here, because it is not exactly a programming question, but I would appreciate if you reply. Thank you.
Here is what I get: (I see that some X11 DISPLAY variable needs to be set, but what value should I give it and how?)
~$ java -jar gate-5.0-beta1-build3048-installer.jar
- ERROR -
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(Graphic sEnvironment.java:159)
at java.awt.Window.<init>(Window.java:407)
at java.awt.Frame.<init>(Frame.java:402)
at net.sourceforge.mlf.metouia.borders.MetouiaDotsBuf fer.<init>(MetouiaDotsBuffer.java:105)
at net.sourceforge.mlf.metouia.borders.MetouiaDots.<i nit>(MetouiaDots.java:66)
at net.sourceforge.mlf.metouia.borders.MetouiaToolBar Border.<init>(MetouiaToolBarBorder.java:49)
at net.sourceforge.mlf.metouia.MetouiaLookAndFeel.ini tComponentDefaults(MetouiaLookAndFeel.java:241)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefault s(BasicLookAndFeel.java:130)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefault s(MetalLookAndFeel.java:1591)
at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:537)
at javax.swing.UIManager.setLookAndFeel(UIManager.jav a:581)
at com.izforge.izpack.installer.GUIInstaller.loadLook AndFeel(GUIInstaller.java:373)
at com.izforge.izpack.installer.GUIInstaller.<init>(G UIInstaller.java:116)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:30
at com.izforge.izpack.installer.Installer.main(Instal ler.java:62)
Source: (StackOverflow)
I just want to share how I found the solution to the error
No realize class procedure defined
when running a X/Motif C application. I am posting this because I only found one reference to this problem while searching online, and it contained no solutions.
I managed to solve the problem and wanted to share my findings if you do come across this problem again (Notice: I am not saying my solution will always solve this type of error).
Problem
I found this problem while running a simple C program that used the Motif and X Intrinsics toolkits.
$ gcc -Wall -c push.c
$ gcc -Wall -o push push.o -lXt -lXm
$ ./push
Error: No realize class procedure defined
The C source code was the following:
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
/* Prototype Callback function */
void pushed_fn(Widget, XtPointer, XmPushButtonCallbackStruct *);
int main(int argc, char **argv)
{
Widget top_wid, button;
XtAppContext app;
Display* display;
XtToolkitInitialize();
app = XtCreateApplicationContext();
display = XtOpenDisplay(app, "localhost:10.0","push","push", NULL,0, &argc,argv);
top_wid = XtAppCreateShell(NULL, "Form", applicationShellWidgetClass, display, NULL, 0);
button = XmCreatePushButton(top_wid, "Push_me", NULL, 0);
/* tell Xt to manage button */
XtManageChild(button);
/* attach fn to widget */
XtAddCallback(button, XmNactivateCallback, (XtCallbackProc) pushed_fn, NULL);
XtRealizeWidget(top_wid); /* display widget hierarchy */
XtAppMainLoop(app); /* enter processing loop */
return 0;
}
void pushed_fn(Widget w, XtPointer client_data, XmPushButtonCallbackStruct *cbs)
{
printf("Don't Push Me!!\n");
}
Source: (StackOverflow)
I used to launch git gui within my cygwin console without any problems but since I updated cygwin I've got the following error message:
$ git gui
Application initialization failed: no display name and no $DISPLAY environment variable
Error in startup script: invalid command name "tk_messageBox"
while executing
"tk_messageBox -icon error -type ok -title "git-gui: fatal error" -message $err"
invoked from within
"if {[catch {package require Tcl 8.4} err]
|| [catch {package require Tk 8.4} err]
} {
catch {wm withdraw .}
tk_messageBox \
-icon error \
-typ..."
(file "/usr/lib/git-core/git-gui" line 34)
Anyone who knows how to solve this?
Source: (StackOverflow)
After update to Mountain Lion, I tried install 1.8.7, and I got error. X11 file not found, I installed Xquarkz, but nothing changed. Whats wrong?
Fail to find [tclConfig.sh, tkConfig.sh]
Use MacOS X Frameworks.
Find Tcl/Tk libraries. Make tcltklib.so which is required by Ruby/Tk.
clang -I. -I../.. -I../../. -I../.././ext/tk -DHAVE_RB_SAFE_LEVEL -DHAVE_RB_HASH_LOOKUP -DHAVE_RB_PROC_NEW -DHAVE_RB_OBJ_TAINT -DHAVE_ST_PTR -DHAVE_ST_LEN -DRUBY_VERSION=\"1.8.7\" -DRUBY_RELEASE_DATE=\"2012-06-29\" -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -DWITH_TCL_ENABLE_THREAD=0 -fno-common -g -O2 -fno-common -pipe -fno-common -c stubs.c
In file included from stubs.c:10:
/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found
# include <X11/Xlib.h>
^
1 error generated.
make[1]: *** [stubs.o] Error 1
make: *** [all] Error 1
Source: (StackOverflow)
I have setup the xvfb server on my headless server and when I m running the
DISPLAY=:99 firefox
I am getting this exception missing RANDR extension
Many of them said to disable some xinerna from the xorg.conf file but this file is not getting created in my case.
So I am searching for how to add the missing RANDR extension.
Source: (StackOverflow)
I am using ubuntu 10.10, and when i compile chromium, it said
remoting/host/event_executor_linux.cc:9: fatal error: X11/extensions/XTest.h: No such file or directory
But i have already installed libx11-dev:
$ sudo apt-get install libx11-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libx11-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Please tell me how can I fix my problem.
Thank you.
Source: (StackOverflow)
I want to create a simple stacking window manager (in C
) for private use, mainly for the purpose of learning and challenging myself.
I've looked through twm
's source code which has relatively few bells and whistles but it seems very low level since it's not based on a widget toolkit.1 Would using a toolkit such as GTK+ be preferable? I'm afraid that some of the code and libraries in twm
might be too antiquated (edit: deprecated) and I want the window manager to use relatively modern libraries. For the sake of understanding I would also be interested in suggestions how to start a window manager from scratch — there aren't many tutorials for this purpose.
Update: For those thinking of similar projects: I ended up using Common Lisp and the CLX library. tinywm-lisp served as a basis and the brilliant CLFSWM and Stumpwm were a great help. For reference I used the CLX — Common LISP X Interface (PDF warning) and #xlib
on Freenode.
Source: (StackOverflow)