Why is background of simple X11 app transparent?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Why is background of simple X11 app transparent?




Pages (2): [1] 2 »   Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Why is background of simple X11 app transparent?  
Matt Garman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-15-05 11:05 PM

I'm trying to learn X11 programming.  I wrote a simple "hello world"
program.

For some reason, the background of the window I create is
transparent (as opposed to black or white, as I specify in my
graphics context).

The simple program is listed below.

Has anyone seen anything like this?

Thanks,
Matt


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
Display *dpy = NULL;
Window window;
char* display_name = NULL;
XFontStruct* font_info;
char* font_name = "fixed";
GC gc;
XGCValues values;
unsigned long valuemask = 0;
int screen_num = 0;


/* create display */
display_name = getenv("DISPLAY");
dpy = XOpenDisplay(display_name);
if (!dpy)
fprintf(stderr, "Can't open display '%s'!\n",
display_name);
screen_num = DefaultScreen(dpy);

/* create window */
window = XCreateWindow(dpy, DefaultRootWindow(dpy),
0, 0, 400, 400, 0, CopyFromParent, CopyFromParent,
CopyFromParent, 0, 0);
XMapWindow(dpy, window);
XFlush(dpy);

/* create graphics context (gc) */
gc = XCreateGC(dpy, window, valuemask, &values);
if (gc < 0) fprintf(stderr, "XCreateGC() failure!\n");
XSetForeground(dpy, gc, WhitePixel(dpy, screen_num));
XSetBackground(dpy, gc, BlackPixel(dpy, screen_num));
XSetLineAttributes(dpy, gc, 10, LineSolid, CapButt, JoinBevel);
XSetFillStyle(dpy, gc, FillSolid);

/* set font */
font_info = XLoadQueryFont(dpy, font_name);
if (!font_info)
fprintf(stderr, "XLoadQueryFont() failed for '%s'\n", font_name);
XSetFont(dpy, gc, font_info->fid);

XSync(dpy, False);

/* draw! draw! draw! */
XDrawString(dpy, window, gc, 40, 40, "Hello World", strlen("Hello World"));

XFillRectangle(dpy, window, gc, 60, 150, 50, 60);

XFlush(dpy);

sleep(10);

XCloseDisplay(dpy);

return 0;
}


--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-15-05 11:05 PM

Matt Garman <fake@not-real.bogus> writes:

> I'm trying to learn X11 programming.  I wrote a simple "hello world"
> program.
>
> For some reason, the background of the window I create is
> transparent (as opposed to black or white, as I specify in my
> graphics context).

It's not transparent, you're just not drawing anything to it.  The
graphics context is only used by the functions that take one as an
argument.  To set a background color for the window, try
XSetWindowBackground.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Matt Garman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 01:54 AM

On Thu, 15 Sep 2005 19:50:01 +0100, Måns Rullgård <mru@inprovide.com> wrote:
> It's not transparent, you're just not drawing anything to it.  The
> graphics context is only used by the functions that take one as an
> argument.  To set a background color for the window, try
> XSetWindowBackground.

Ahh, indeed.  Actually, for this exercise, I just switched to
XCreateSimpleWindow(), and used BlackPixel and WhitePixel for my
foreground and background colors.

Now I have a new question... whenever I create a window, the window
manager overwrites the top portion of my window with the titlebar.
I guess I assumed that the window manager would "grow" its titlebar
upward from the top of my window.

How can I possibly know what the window manager's titlebar height
is?  To even provide such a function seems out of scope for X.  Am I
supposed to set some kind of hint to the window manager?

Thanks again,
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Russell Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 07:48 AM

Matt Garman wrote:
> On Thu, 15 Sep 2005 19:50:01 +0100, Måns Rullgård <mru@inprovide.com> wrot
e:
> 
>
> Ahh, indeed.  Actually, for this exercise, I just switched to
> XCreateSimpleWindow(), and used BlackPixel and WhitePixel for my
> foreground and background colors.
>
> Now I have a new question... whenever I create a window, the window
> manager overwrites the top portion of my window with the titlebar.
> I guess I assumed that the window manager would "grow" its titlebar
> upward from the top of my window.
>
> How can I possibly know what the window manager's titlebar height
> is?  To even provide such a function seems out of scope for X.  Am I
> supposed to set some kind of hint to the window manager?
>
> Thanks again,
> Matt

The client is meant to know about the window manager border.

All this is explained in the ICCCM.

http://www.google.com.au/search?hl=...le+Search&meta=





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 07:48 AM

Matt Garman <fake@not-real.bogus> writes:

> Now I have a new question... whenever I create a window, the window
> manager overwrites the top portion of my window with the titlebar.
> I guess I assumed that the window manager would "grow" its titlebar
> upward from the top of my window.

Are you sure about this?  Which window manager are you using?  The
ones I've used (including twm, mwm, olvwm, fvwm, sawfish, metacity,
kwin, enlightenment, blackbox) have never done anything like this.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Matt Garman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 11:01 PM

On Fri, 16 Sep 2005 08:20:39 +0100, Måns Rullgård <mru@inprovide.com> wrote:
> Are you sure about this?  Which window manager are you using?  The
> ones I've used (including twm, mwm, olvwm, fvwm, sawfish,
> metacity, kwin, enlightenment, blackbox) have never done anything
> like this.

Yup, quite sure---it's actually part of the reason I was intially
unable to see what was being drawing to my window.  I can take some
screenshots later, if you're interested.

The WM I'm using is enlightenment 0.16.7.2.  This is on gentoo Linux
on i386.

I haven't yet tried other window managers---I'll try that also
(much later today).

Thanks again!
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 11:01 PM

Matt Garman <fake@not-real.bogus> writes:

> On Fri, 16 Sep 2005 08:20:39 +0100, Måns Rullgård <mru@inprovide.com> wrot
e: 
>
> Yup, quite sure---it's actually part of the reason I was intially
> unable to see what was being drawing to my window.  I can take some
> screenshots later, if you're interested.

I'd rather see some code that creates a window with that behavior.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Matt Garman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-05 11:01 PM

On Fri, 16 Sep 2005 18:41:02 +0100, Måns Rullgård <mru@inprovide.com> wrote:
 
>
>  I'd rather see some code that creates a window with that behavior.

This code exhibits said behavior (window manager title bar
overwriting top portion of window).



#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
Display *dpy = NULL;
Window window;
char* display_name = NULL;
XFontStruct* font_info;
/* picking a larger font, as my default "fixed" font is so small that it
* will be completely overwritten by the titlebar */
char* font_name = "10x20";
GC gc;
XGCValues values;
unsigned long valuemask = 0;
int screen_num = 0;


/* create display */
display_name = getenv("DISPLAY");
dpy = XOpenDisplay(display_name);
if (!dpy) {
fprintf(stderr, "Can't open display '%s'!\n",
display_name);
}
screen_num = DefaultScreen(dpy);

/* create window */
window = XCreateWindow( dpy, DefaultRootWindow(dpy), 0, 0, 400, 400, 0,
CopyFromParent, CopyFromParent, CopyFromParent, 0, 0);
XMapWindow(dpy, window);
XFlush(dpy);

/* create graphics context (gc) */
gc = XCreateGC(dpy, window, valuemask, &values);
if (gc < 0) {
fprintf(stderr, "XCreateGC() failure!\n");
}
XSetForeground(dpy, gc, WhitePixel(dpy, screen_num));
XSetBackground(dpy, gc, BlackPixel(dpy, screen_num));
XSetLineAttributes(dpy, gc, 10, LineSolid, CapButt, JoinBevel);
XSetFillStyle(dpy, gc, FillSolid);

/* set font */
font_info = XLoadQueryFont(dpy, font_name);
if (!font_info) {
fprintf(stderr, "XLoadQueryFont() failed for '%s'\n", font_name);
}
XSetFont(dpy, gc, font_info->fid);

XSync(dpy, False);

/* draw! draw! draw! */
XDrawString(dpy, window, gc, 40, 40, "Hello World", strlen("Hello World"));
XFillRectangle(dpy, window, gc, 60, 150, 50, 60);

XFlush(dpy);

sleep(10);
XCloseDisplay(dpy);

return 0;
}


--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Måns Rullgård


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-17-05 07:48 AM

Matt Garman <fake@not-real.bogus> writes:

> On Fri, 16 Sep 2005 18:41:02 +0100, Måns Rullgård <mru@inprovide.com> wrot
e: 
>
> This code exhibits said behavior (window manager title bar
> overwriting top portion of window).

Works just fine here.  Your window manager is broken.

--
Måns Rullgård
mru@inprovide.com





[ Post a follow-up to this message ]



    Re: Why is background of simple X11 app transparent?  
Matt Garman


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-20-05 11:05 PM

On Sat, 17 Sep 2005 02:48:38 +0100, Måns Rullgård <mru@inprovide.com> wrote:
>  Matt Garman <fake@not-real.bogus> writes: 
>
>  Works just fine here.  Your window manager is broken.

What window manager are you using?

FWIW, I got the same behavior under enlightenment 0.16.7.2 and
fluxbox 0.9.14.

When I tried it under FVWM 2.5.12, I have the same problem I
originally posted about (the background is "transparent" and no
drawn features show up in the window).

Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:44 PM.      Post New Thread    Post A Reply      
Pages (2): [1] 2 »   Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register