LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can I create an Xwin Window from a Console App when Xwin is running? (http://www.linuxquestions.org/questions/linux-newbie-8/can-i-create-an-xwin-window-from-a-console-app-when-xwin-is-running-814784/)

will_kranz 06-17-2010 03:22 PM

Can I create an Xwin Window from a Console App when Xwin is running?
 
I'm not new to linux but am fairly new to Xwin. I have a well structured console application to which I'd like to add graphics output. I could port it to Xwin, but that's a pain, I just want to display some graphics. Is this doable? I seem to be able to make the calls, but the window never appears. If I do the same calls (which seem to return the same valid values) from a Xwin application it all works fine. What's going on?

Is it as simple as configuring my console to a different mode? I find I can't execute this application from an X browser either, and I thought I used to be able to do that. IE click on a console application and have it open a console box and run the application.

Thanks, Will

Tinkster 06-17-2010 09:05 PM

You're being caught out by X' security (most likely) ...

To make it work on your local machine you'll need to do two things:
a) in the active X11 session (as the user owning the session) permit
local X11 programs to display:
Code:

xhost +localhost
b) from your console:
Code:

export DISPLAY=:0.0

If that doesn't resolve your problem, try running your program under
strace control, and see whether that gives you insight as to why it's
failing to do your bidding.


Cheers,
Tink

will_kranz 06-19-2010 07:52 AM

thanks for the tips, afraid I still don't get a) above.
b) I understand, but where would I enter/do config for a)?

I am currently running a KDE style front end to Xwin. I looked at the console configuration options, and see nothing like that.
Can you hold my hand a little more and tell me where to go to set this up?

Again, thanks for the helping hand, it would be much easier if I can get it to work this way...

Tinkster 06-19-2010 07:32 PM

Maybe we need to clarify terms first. When you say 'console', are
you talking about a full-screen ASCII terminal outside the GUI, or
an xterm llook-alike like konsole?

What *I* thought you meant was that you have a program that you
want to be able to run as any user from any console (the full screen
one) and display on the same machines X11 graphical subsystem.


The a) above grants any process from the local machine to display
graphical content in the current X11 session (or the first one, to
be pedantic - you could obviously have more than one X session going
at the same time). The "xhost +localhost" needs to be issued in
the running X session.



Cheers,
Tink

will_kranz 06-20-2010 08:22 PM

Unfortunately you are confusing me more rather than less.

The first question I am trying to ask is where/how am I to
issue the command you suggest:
"The "xhost +localhost" needs to be issued in
the running X session."
Ok I have the KDE desktop up and running, where am I supposed to do this? Its a GUI not a command line interface, puzzled.
Is there a configuration window/screen I should be in, if so where?


Oh wait, maybe I get it, 'xhost' is a program I run in console mode. I'll try that.


Further in my experience, If I run the Xserver with the KDE, or
any other front end, I can not at the same time have any 'real full fledged consoles' at all. All I can have are emulated console boxes which I open from the start menu. These act much like the full screen consoles I can open if X is not running, but are X aware. Its one of these console boxes under Xwin that I want to use to run my text mode application. I think it probably is a kconsole.

Tinkster 06-20-2010 08:25 PM

Quote:

Originally Posted by will_kranz (Post 4009664)
Unfortunately you are confusing me more rather than less.

The first question I am trying to ask is where/how am I to
issue the command you suggest:
"The "xhost +localhost" needs to be issued in
the running X session."
Ok I have the KDE desktop up and running, where am I supposed to do this? Its a GUI not a command line interface, puzzled.
Is there a configuration window/screen I should be in, if so where?

Open any terminal (konsole, xterm, rxvt, ... ) and enter
xhost +localhost

Quote:

Originally Posted by will_kranz (Post 4009664)
Further in my experience, If I run the Xserver with the KDE, or
any other front end, I can not at the same time have any 'real full fledged consoles' at all. All I can have are emulated console boxes which I open from the start menu. These act much like the full screen consoles I can open if X is not running, but are X aware. Its one of these console boxes under Xwin that I want to use to run my text mode application. I think it probably is a kconsole.

That should just work then. If you're running your app
as the user who owns the X-session, and it doesn't change
privileges after you start it it should actually "just work".

will_kranz 06-23-2010 11:10 AM

I think I solved it
 
Tinkster seems to be the only one watching this, but just in case someone else comes along, I was making a big newbie mistake. The xhost and security issue is interesting, but was not my problem.

It was more fundmental. I had not read the manual carefully and did not realize that Xwin queues requests to the server. I did all my setup,
including an XMapRaised() call. But I never called XNextEvent() which has the side effect of sending all the pending requests to the server! Sigh.
Live and learn.

I now have a new problem, namely the new window I have created seems to
have control now and I can't get it to go back to the original console window for input processing which is what I need. But lets consider this solved and I will read the Xlib Ref further before asking more questions!

Thanks.

Tinkster 06-23-2010 02:38 PM

Well done, and pity my ideas were off on a tangent. I guess
I didn't think of a coding issue on your side :}


Cheers,
Tink


All times are GMT -5. The time now is 05:40 PM.