LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-09-2019, 09:44 PM   #1
jr_bob_dobbs
Member
 
Registered: Mar 2009
Distribution: Slackware, Linux From Scratch, Bedrock
Posts: 375
Blog Entries: 51

Rep: Reputation: 49
proper xorg background setting in my program


So I've written a program and part what what said program does is set a picture to be the background wallpaper in xorg. This works, with one oddity: programs like urxvt do not correctly show my background through their transparency. If I set the background wallpaper using feh, then that background shows through. In fact, if I first set the wallpaper to one picture with feh and *then* set the wallpaper to a second picture using my program, the wallpaper will change to the second picture, but a subsequent run of urxvt will show the first picture within its transparent window!

I've looked at the source for feh and was confused.

My theory is that there is more than one way to set the background wallpaper and, while the way I am doing it works, it is not the proper way.

Web searching has not revealed anything, oddly enough.

Here is a snippit of the wallpaper-setting part of my program:
Code:
int wall_it(fn)
char *fn;  /* file to read and wall */
{
  /* file is assumed to be same width and height as screen:
     behavior is undefined otherwise */
  Imlib_Image img;
  Display *dpy;
  Pixmap pix;
  Window root;
  Screen *scn;
  int wi_width, wi_height;

  /* open up imlib / x-windows stuff */
  img = imlib_load_image(fn);
  if (!img) {
    fprintf(stderr, "wall_it: error loading image\n");
    return(DOOPS);
  }
  imlib_context_set_image(img);

  /* get image dimensions */
  wi_width = imlib_image_get_width();
  wi_height = imlib_image_get_height();

  dpy = XOpenDisplay(NULL);
  if (!dpy) {
    fprintf(stderr, "wall_it: XOpenDisplay error\n");
    return(DOOPS);
  }
  scn = DefaultScreenOfDisplay(dpy);
  root = DefaultRootWindow(dpy);

  pix = XCreatePixmap(
    dpy, root, wi_width, wi_height,
    DefaultDepthOfScreen(scn)
  );

  imlib_context_set_display(dpy);
  imlib_context_set_visual(DefaultVisualOfScreen(scn));
  imlib_context_set_colormap(DefaultColormapOfScreen(scn));
  imlib_context_set_drawable(pix);

  /* actually wall that picture */
  imlib_render_image_on_drawable(0, 0);
  XSetWindowBackgroundPixmap(dpy, root, pix);
  XClearWindow(dpy, root);

  while (XPending(dpy)) {
    XEvent ev;
    XNextEvent(dpy, &ev);
  }

  /* clean up */
  XFreePixmap(dpy, pix);
  imlib_free_image();
  XCloseDisplay(dpy);

  /* done */
  return(OKDOKEY);
}
Again, my program actually works, in that I see the picture become the new background wallpaper.

Thank you.
 
Old 10-10-2019, 12:36 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: FreeBSD/Slackware-14.2+/ArcoLinux
Posts: 9,133

Rep: Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925Reputation: 1925
you can take a look at some code of mine using imlib2 in a dockapp that sets images to dt, I have to figure it out again every time I play around with it, and have no done so in a very long time. but you should find it interesting. You might find a few things interesting in how to do tiling and such as well and hopefully it will help you to see other ways to do this using imlib2 headers.
Code:
 XSetWindowBackgroundPixmap (display, RootWindow (display, 0), pixmap);
you want rootWindow not the layer above it.
--------------- MOD------------------


Okay, with your code you posted I modded it to work with just what you posted and it was not working using the function call with and without RootWindow, then I got an older program I heavily modified using Imlib and tried that and it works like it should with urxvt and seeing the replaced image on the desktop.
Code:
- For fake transparency  ~/.Xdefaults :

urxvt*transparent: true
urxvt*shading: 30
using that to set its transparency to test this.


Manipulating the Atoms and changing the desktop settings, updating them this works like you're looking for it to work. It is defiantly a little more complex needing more code to get what you want it to do.

Then I remembered another one I did, so if you are interested in looking at what I did to get what you're looking to do, then go to mhsetroot and download it then look at my source code, it is written in C and it features , resize the images to whatever the user wants then set it to the desktop , and a few more functions for added options on how to display the image on the desktop along with the colors too.

You will find your solution within that code.
Attached Files
File Type: txt setBG.cpp.txt (13.5 KB, 1 views)

Last edited by BW-userx; 10-10-2019 at 05:57 PM.
 
Old 10-10-2019, 01:54 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,463
Blog Entries: 9

Rep: Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372Reputation: 3372
Quote:
Originally Posted by jr_bob_dobbs View Post
So I've written a program and part what what said program does is set a picture to be the background wallpaper in xorg. This works, with one oddity: programs like urxvt do not correctly show my background through their transparency. If I set the background wallpaper using feh, then that background shows through. In fact, if I first set the wallpaper to one picture with feh and *then* set the wallpaper to a second picture using my program, the wallpaper will change to the second picture, but a subsequent run of urxvt will show the first picture within its transparent window!
I have recently experienced the exact same with xplanet.
Xplanet has a "-transparency" option that specifically addresses that problem. Maybe you should look at the source of that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
A proper way to config Xorg to use TFT ? muttley.meen Debian 0 08-20-2006 09:24 AM
Change background in solaris and Xterm background also EvilAngel Solaris / OpenSolaris 2 01-31-2005 11:25 AM
Background and Xterm transparent background EvilAngel Linux - General 1 01-31-2005 09:40 AM
In KDE, aterm uses GNOME background rather than KDE background for transparent backgr cpbl Linux - Software 4 01-01-2005 10:26 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:32 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration