LinuxQuestions.org
Visit Jeremy's Blog.
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-06-2017, 02:13 PM   #1
Roy_SRC
Member
 
Registered: Jul 2014
Posts: 81

Rep: Reputation: Disabled
how to set background image on display xlib


Hi,

I'm a newbie to linux XServer and X11 in general, so, I'm not quite sure as to if this question goes in the linux newbie forum or the programming forum. Anyways, I'm using Xlib to work with the Xserver, and I was wondering if anyone could tell me or point me to a block of code that I can use to set the background of the display or the screen (not the window) to an image rather than just have the it all black or white.

Thanks!

Last edited by Roy_SRC; 01-06-2017 at 02:32 PM.
 
Old 01-06-2017, 04:56 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Usually that function is handled by the desktop of your choice.

Missing that - there is xsetroot which allows you to change various aspects/coloring of the background.

There are other tools - specifically in the Imagemagic package that allows various images to be put on the background using the "xloadimage" tool.

But usually, it is done by some tool of the desktop you are using.

One thing that can happen when mixing the desktop and using external tools is that sometimes the "refresh" of the display (multiple workspaces for instance) will replace the image with what that desktop tool is using.

Last edited by jpollard; 01-06-2017 at 04:58 PM.
 
Old 01-06-2017, 05:46 PM   #3
Roy_SRC
Member
 
Registered: Jul 2014
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jpollard View Post
Usually that function is handled by the desktop of your choice.

Missing that - there is xsetroot which allows you to change various aspects/coloring of the background.

There are other tools - specifically in the Imagemagic package that allows various images to be put on the background using the "xloadimage" tool.

But usually, it is done by some tool of the desktop you are using.

One thing that can happen when mixing the desktop and using external tools is that sometimes the "refresh" of the display (multiple workspaces for instance) will replace the image with what that desktop tool is using.
I should've mentioned this in the question, but there is no desktop environment or window manager, it's just a fresh copy of arch and x, and I just wanted to write almost everything from the bottom up just to teach myself how to work with the bare xserver. The way I'm setting a background now is by creating a window the size of the display screen and setting that window to be the root of all other windows, and setting the background of that root window. What I want to do right now is have the image directly displayed on the screen and not on the window. Do you think it is possible to maybe do that.
 
Old 01-06-2017, 07:22 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
It sounds like you've already looked into this, but Feh does it via calls to imlib2.

Last edited by dugan; 01-06-2017 at 07:24 PM.
 
Old 01-07-2017, 06:43 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by Roy_SRC View Post
I should've mentioned this in the question, but there is no desktop environment or window manager, it's just a fresh copy of arch and x, and I just wanted to write almost everything from the bottom up just to teach myself how to work with the bare xserver. The way I'm setting a background now is by creating a window the size of the display screen and setting that window to be the root of all other windows, and setting the background of that root window. What I want to do right now is have the image directly displayed on the screen and not on the window. Do you think it is possible to maybe do that.
i am alittle unsure whther you are asking for a utility that does that at login, or whether you are writing a C program that is supposed to do that?

if the former, the advice given so far is correct.
there's a multitude of utilities that will do what you want: setroot, hsetroot, xsetroot, feh, nitrogen...

and you need to add that command to your autostart script so it gets excuted everytime you log in.

if the latter, i cannot help with programming.
 
Old 01-07-2017, 12:52 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
likely the simplest is xloadimage. It also would allow you to put multiple images (in different places) on the display.
 
Old 01-15-2017, 05:31 PM   #7
DeeDeeK
Member
 
Registered: Jan 2016
Distribution: Ubuntu 14.04
Posts: 37

Rep: Reputation: Disabled
It doesn't matter how you load or create the background image, as I understand your question. But you just want to know how to put an image at the very back, so anything else is drawn in front of it? Like if the root window was invisible, you'd still see an image?

In X, as far as I get it, the root window IS the back. I know you can juggle things around, but that's it. X doesn't render outside of a drawable, and the drawable which you can see is a window, mapped to the screen.

Perhaps you mean drawing to the framebuffer? But you can create the root window with a backing store so it automagically buffers itself so you don't need to respond to expose events just to keep the image intact, you can sort of set and forget. For multiple screens, I dunno.
 
Old 01-15-2017, 05:41 PM   #8
DeeDeeK
Member
 
Registered: Jan 2016
Distribution: Ubuntu 14.04
Posts: 37

Rep: Reputation: Disabled
Manual for Xlib programming very very helpful

https://tronche.com/gui/x/

Check out the above URL.

Below is a descriptive quote, clipped from the page pointed to by the above URL

Quote:
This is the conversion of the Xlib Programming Manual into HTML, brought to you by Christophe Tronche. This work is far from being complete, as you may soon notice, and is provided "as is" ("as usual"). Many links have been made provision for, but actually aren't translated yet. If you're more interested in some part of the manual, let me know and I'll push further on it.

By popular demand, you can now get the manual as one .tar.gz file (~ 330 Kb).

How to get a PostScript version of the manual.

This work is based on X11 release 6.

The X11/Xlib manual is copyrighted by the X Consortium.
 
  


Reply

Tags
x11, xlib, xserver



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
Read and display an image with Xlib leistebien Programming 3 10-10-2011 11:28 AM
[SOLVED] How can I set a root background image? CFet Slackware 3 04-04-2011 09:46 PM
Set background image for Konsole 2??? cweepy Linux - Newbie 2 09-08-2008 11:16 AM
Can't set background image in Icewm gamfa Grafpup 1 06-28-2007 10:28 AM
How to set the login background image when using KDM PTrenholme Fedora 0 04-15-2006 09:20 AM

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

All times are GMT -5. The time now is 10:25 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