LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2017, 08:02 PM   #1
Roy_SRC
Member
 
Registered: Jul 2014
Posts: 81

Rep: Reputation: Disabled
X11: Translucency not working when the window's parent is not the root window


I am trying to get translucency to work when creating X windows using C and Xlib. Here's my code:

Code:
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <Imlib2.h>

int main(int argc, char **argv)
{
    Imlib_Image img;
    Display *dpy;
    Window root;
    int scnNum;

    int width, height;
    const char *filename = argv[1];

    dpy = XOpenDisplay(NULL);
    if (!dpy) return 0;

    scnNum = DefaultScreen(dpy);
    root = DefaultRootWindow(dpy);

    XVisualInfo vinfo;
    Status ret = XMatchVisualInfo(dpy, scnNum, 32, TrueColor, &vinfo);
    
    // Create a top-level window (with no alpha channel)
    Window win = XCreateSimpleWindow(dpy, root,
                                     0, 0, 500, 500, 0,
                                     WhitePixel(dpy, 0), BlackPixel(dpy, 0));
    
    // Draw an image on the window
    img = imlib_load_image("sampleImage.jpg");

    imlib_context_set_image(img);
    width = imlib_image_get_width();
    height = imlib_image_get_height();
    
    Pixmap pix = XCreatePixmap(dpy, win, width, height, DefaultDepth(dpy, scnNum));
    
    imlib_context_set_display(dpy);
    imlib_context_set_visual(DefaultVisual(dpy, scnNum));
    imlib_context_set_colormap(DefaultColormap(dpy, scnNum));
    imlib_context_set_drawable(pix);
    
    imlib_render_image_on_drawable(0, 0);
    XSetWindowBackgroundPixmap(dpy, win, pix);
    
    // Map window on display
    XMapWindow(dpy, win);
    
    // Create a child window with alpha channel
    XSetWindowAttributes attrChild;
    attrChild.colormap = XCreateColormap(dpy, root, vinfo.visual, AllocNone);
    attrChild.border_pixel = 1;
    attrChild.background_pixel = 0x20423444;
    attrChild.background_pixmap = None;
    
    Window childWin = XCreateWindow(dpy, win,
                                    10, 10, 200, 200, 1,
                                    vinfo.depth,
                                    InputOutput,
                                    vinfo.visual,
                                    CWColormap | CWBorderPixel | CWBackPixel | CWBackPixmap,
                                    &attrChild);
      
    // Map child window on display
    XMapWindow(dpy, childWin);
    
    // Event loop
    while (1) {
      XEvent event;
      XNextEvent(dpy, &event);
    }

    XCloseDisplay(dpy);
    return 0;
}
First, I run xcompmgr -c

Then, I run my program and this is what I get:

Click image for larger version

Name:	withWin.jpg
Views:	56
Size:	38.1 KB
ID:	24019

I don't get any translucency. But here's the strange part: if I change the parent of childWin to be root:

Code:
    Window childWin = XCreateWindow(dpy, root,
                                    10, 10, 200, 200, 1,
                                    vinfo.depth,
                                    InputOutput,
                                    vinfo.visual,
                                    CWColormap | CWBorderPixel | CWBackPixel | CWBackPixmap,
                                    &attrChild);
This is what I get:

Click image for larger version

Name:	withRoot.jpg
Views:	53
Size:	39.5 KB
ID:	24018

I get some kind of translucency. I want childWin to be a child of win and I want to preserve translucency, but I have no idea what I'm doing wrong.

Thanks!

Last edited by Roy_SRC; 01-19-2017 at 08:05 PM.
 
  


Reply

Tags
x server, x11, xlib



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ascertain the parent window border color used by the WM xbunny Programming 6 05-21-2016 10:34 AM
Starting new terminal window or tab from existing window remaining as root? homerun Linux - Newbie 1 08-14-2009 11:34 AM
How to turn OFF window translucency in KDE/Fedora? RileyTheWiley Linux - Newbie 1 05-03-2008 09:06 PM
xwindows, how can a client window be notified when parent window is moved/resized? shamju Linux - Desktop 1 02-03-2007 07:30 PM
How do I reattach floating window to its parent? bscbrit Linux - Newbie 3 09-24-2003 10:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration