LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-20-2007, 10:54 AM   #1
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246
Blog Entries: 1

Rep: Reputation: 31
Question How to "Show desktop" in xfce4?


I know of the taskbar icon for that but i want to assign a keyboard shortcut for that.
What would be the command for showing desktop( minimize all toggle)
for xfce4?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-21-2007, 10:08 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by ciden View Post
What would be the command for showing desktop( minimize all toggle)
for xfce4?
Unfortunately, the xfce4 Showdesktop is implemented as a panel plugin (which means the only way to toggle through xfce’s interface is to use the button). So there is no xfce command (of which I am aware) which will let you execute it to toggle the “show desktop” state). The reason this is unfortunate is that (for the most part) the targets of keyboard shortcuts are “commands” (i.e., something executable), but there is no command (that I know of) which will allow you to push a specific panel button.

Fortunately, if you know a little Xlib, it is pretty easy to make your own command which toggles the “show desktop” on all window managers which support it (to support the “show desktop” feature, a wm should conform to part of the EWMH document). And we’re in luck, because Xfce (among other WMs) does support this extension.

So here’s the code. First, it queries the root window as to the state of the “show desktop” property, then, it sends a request to make the “show desktop” property the opposite of whatever it was found to be.
Code:
#include <X11/Xatom.h>
#include <X11/Xlib.h>

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	Display *d;
	Window root;
	Atom _NET_SHOWING_DESKTOP, actual_type;
	int actual_format, error, current;
	unsigned long nitems, after;
	unsigned char *data = NULL;

	/* Open the default display */
	if(!(d = XOpenDisplay(NULL))) {
		fprintf(stderr, "Cannot open display \"%s\".\n", XDisplayName(NULL));
		exit(EXIT_FAILURE);
	}

	/* This is the default root window */
	root = DefaultRootWindow(d);

	/* find the Atom for _NET_SHOWING_DESKTOP */
	_NET_SHOWING_DESKTOP = XInternAtom(d, "_NET_SHOWING_DESKTOP", False);

	/* Obtain the current state of _NET_SHOWING_DESKTOP on the default root window */
	error = XGetWindowProperty(d, root, _NET_SHOWING_DESKTOP, 0, 1, False, XA_CARDINAL,
	                           &actual_type, &actual_format, &nitems, &after, &data);
	if(error != Success) {
		fprintf(stderr, "Received error %d!\n", error);
		XCloseDisplay(d);
		exit(EXIT_FAILURE);
	}

	/* The current state should be in data[0] */
	if(data) {
		current = data[0];
		XFree(data);
		data = NULL;
	}

	/* If nitems is 0, forget about data[0] and assume that current should be False */
	if(!nitems) {
		fprintf(stderr, "Unexpected result.\n");
		fprintf(stderr, "Assuming unshown desktop!\n");
		current = False;
	}

	/* Initialize Xevent struct */
	XEvent xev = {
		.xclient = {
			.type = ClientMessage,
			.send_event = True,
			.display = d,
			.window = root,
			.message_type = _NET_SHOWING_DESKTOP,
			.format = 32,
			.data.l[0] = !current /* That’s what we want the new state to be */
		}
	};

	/* Send the event to the window manager */
	XSendEvent(d, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);

	XCloseDisplay(d);
	exit(EXIT_SUCCESS);

	return 0;
}
So to compile the thing, first just copy-and-paste the code to a text file (for our purposes, I’ll call it sdtoggle.c). Then, compile it (you’ll have to have libX11 and its headers installed on your system):
Code:
gcc -o sdtoggle -lX11 sdtoggle.c
Now, you have an executable (namely, sdtoggle) which should toggle the “show desktop” property (try it out in a terminal and look for any error messages):
Code:
./sdtoggle; sleep 2; ./sdtoggle
Once you’ve verified that it works as intended (the above line should minimize all windows, pause for two seconds, and then reopen those windows which were minimized), you can go ahead and place it somewhere safe (e.g., /usr/local/bin). Then add a keyboard shortcut that executes the new command, and you should be set.

Last edited by osor; 11-23-2007 at 10:05 AM. Reason: Add comments as requested
 
1 members found this post helpful.
Old 11-23-2007, 08:30 AM   #3
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246

Original Poster
Blog Entries: 1

Rep: Reputation: 31
I will try that out. Isnt there a target for the panel button?
btw fluxbox has command for show desktop toggle. I love fluxbox but KDE apps start very slowly. But I find it the besst if runnning any hevy program like GIMP or Blender.
 
Old 11-23-2007, 08:32 AM   #4
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246

Original Poster
Blog Entries: 1

Rep: Reputation: 31
btw could you plz put a few comments in the above code. I would like to understand it better.
 
Old 11-23-2007, 10:05 AM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by ciden View Post
Isnt there a target for the panel button?
I assume you mean a way to make a keyboard shortcut be the equivalent of clicking the panel button, and AFAICS, the answer is no.
Quote:
Originally Posted by ciden View Post
btw fluxbox has command for show desktop toggle.
By “command” do you mean through something (e.g., fluxbox-remote) or an actual, window-manager-agnostic command? While searching for the command you referenced, the closest thing I could find was wmctrl (which does seem to implement “show desktop” support, but not as a toggle). So I guess if you want, you could use “wmctrl -k on” and “wmctrl -k off” instead.
Quote:
Originally Posted by ciden View Post
btw could you plz put a few comments in the above code. I would like to understand it better.
Sure. I’ve also put in a small workaround for Xfce (which seems to set nitems to zero if it has never been toggled since it started—in that case, it is safe to assume the current desktop state is “unshown”). This document (and these sections of it) explain most of the reasons for the various settings.
 
1 members found this post helpful.
Old 11-24-2007, 01:30 AM   #6
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246

Original Poster
Blog Entries: 1

Rep: Reputation: 31
Well if you have used fluxbox, u must know the .fluxbox/keys file.
I have an entry there

Mod4 d :ShowDesktop

which maps WIN key + 'd' for toggle show desktop.
 
Old 11-24-2007, 02:28 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Yes, I am familiar with “fluxbox commands” (also called “fluxbox actions”). The only problem is that they work only on fluxbox. I was looking for a command-line “command” which works on both fluxbox and xfce. The closest I found was wmctrl. The commands “wmctrl -k on” and “wmctrl -k off” do in fact work on xfwm4 (from Xfce), metacity (from Gnome), Kwin (from KDE), E (from Enlightenment), icewm, and others. They do not work on fluxbox (as it does not implement the relevant part of the EWMH spec). On fluxbox (assuming you have allowRemoteActions enabled in your init), you have to do “fluxbox-remote ShowDesktop” instead.
Quote:
Originally Posted by ciden View Post
for toggle show desktop.
Not exactly toggle. The key combination you made shows the desktop. There is currently no way in fluxbox to unshow the desktop, but you can do something almost as good—deiconify all windows. E.g.,
Code:
Mod4 d :ToggleCmd {ShowDesktop} {DeIconify all originquiet}
does almost what you intended.

Bottom line:
In fluxbox,
  1. If you want to “show the desktop” use the fluxbox action “ShowDesktop” (this can be in config files or directly with “fluxbox-remote ShowDesktop”).
  2. There is currently no way to “unshow” a shown desktop. You can, however, deiconify all windows in a workspace using the fluxbox action “DeIconify” applied to all windows in a workspace.
  3. You cannot ascertain the current state of the desktop showing, so you cannot send a single command for toggling its showing. What you can do to toggle showing of the desktop is to let fluxbox’s keygrabber manage keeping track of the state as in the sample above.
  4. The code from post 2, “wmctrl -k on”, and “wmctrl -k off” will have no effect until fluxbox decides to implement the relevant part of the EWMH standard.
In Xfce (and many other of the “mainstream” window managers),
  1. You can show the desktop with “wmctrl -k on”.
  2. You can unshow a shown desktop with “wmctrl -k off”.
  3. You can toggle the state of showing a desktop using the code from post 2.
  4. You cannot use fluxbox actions.

Last edited by osor; 11-24-2007 at 06:01 PM.
 
Old 11-26-2007, 09:25 AM   #8
ciden
Member
 
Registered: Dec 2006
Location: New Delhi, India
Distribution: PCLinuxOS 2010
Posts: 246

Original Poster
Blog Entries: 1

Rep: Reputation: 31
Thank you very much. Will try it ASAP.
I have examinations going on, and they are not about computers.
I am Microbiology.
 
Old 12-18-2007, 02:06 AM   #9
clark_kent
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 3
Actually XFCE has this feature built in. The way to use it is to go to xfce's "Window manager" configuration and set a keybinding for the action "Show Desktop." I have it set to Super+D. It does not explicitly say this, but when I press super+d once, it minimizes all my windows. When I do it a second time, it restores all of my previously opened windows.
 
3 members found this post helpful.
Old 01-03-2009, 11:02 AM   #10
blahdeblah
LQ Newbie
 
Registered: Jan 2009
Posts: 1

Rep: Reputation: 1
xprop tool

Also you can simply see the current value using the tool 'xprop':

example:
xprop -root _NET_SHOWING_DESKTOP

so you can probably do something like this in a bash script to toggle it:
Code:
if xprop -root  _NET_SHOWING_DESKTOP|egrep '= 1' ; then 
  wmctrl -k off ; 
else 
  wmctrl -k on ;
fi
 
Old 12-13-2011, 07:17 PM   #11
AntonyDeepak
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
CNTL + ALT + D works to 'Show desktop' in my computer.
 
Old 09-09-2012, 02:36 PM   #12
neoh4x0r
LQ Newbie
 
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by AntonyDeepak View Post
CNTL + ALT + D works to 'Show desktop' in my computer.
That's because this is the default keybinding in xfce

Quote:
Originally Posted by clark_kent View Post
Actually XFCE has this feature built in. The way to use it is to go to xfce's "Window manager" configuration and set a keybinding for the action "Show Desktop." I have it set to Super+D. It does not explicitly say this, but when I press super+d once, it minimizes all my windows. When I do it a second time, it restores all of my previously opened windows.
You can edit the Window Manger settings by going to Settings->Settings Manger (or running xfce4-settings-manager then clicking Window Manager)
Access Xfce4 Window Manager settings

You can edit the Window Manger keybindings by foing to Settings->Settings Manager->Window Manager-> click keyboard tab (then type: show d[esktop] :: it will take you to the setting)
Show Desktop Setting /w default keybinding (primary is left Control key)

Last edited by neoh4x0r; 09-09-2012 at 02:45 PM.
 
1 members found this post helpful.
Old 09-17-2017, 10:03 PM   #13
jerome1872000
LQ Newbie
 
Registered: Sep 2017
Posts: 3

Rep: Reputation: Disabled
Quote:
Originally Posted by ciden View Post
I know of the taskbar icon for that but i want to assign a keyboard shortcut for that.
What would be the command for showing desktop( minimize all toggle)
for xfce4?
where is the taskbar icon for showing the desktop in xfce? I do not see one, nor does one appear to be in the panal config for it..
 
Old 09-18-2017, 01:58 AM   #14
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 jerome1872000 View Post
where is the taskbar icon for showing the desktop in xfce? I do not see one, nor does one appear to be in the panal config for it..
have you looked at the post date?
don't necrobump.
take the time to formulate a proper problem description.
take the time to search for a solution.
only when that doesn't help, start a new thread.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
Kde "show desktop" icon / real player plug in alek66 Linux - General 3 06-19-2006 10:33 AM
About the "show desktop" -button in gnome raaste Linux - Software 5 05-22-2006 04:25 PM
"Show Desktop" button for GNOME ministre Linux - General 2 10-22-2003 06:46 PM

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

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