LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to "Show desktop" in xfce4? (https://www.linuxquestions.org/questions/linux-software-2/how-to-show-desktop-in-xfce4-601161/)

ciden 11-20-2007 10:54 AM

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?

osor 11-21-2007 10:08 PM

Quote:

Originally Posted by ciden (Post 2965459)
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.

ciden 11-23-2007 08:30 AM

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.

ciden 11-23-2007 08:32 AM

btw could you plz put a few comments in the above code. I would like to understand it better.

osor 11-23-2007 10:05 AM

Quote:

Originally Posted by ciden (Post 2968410)
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 (Post 2968410)
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 (Post 2968411)
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.

ciden 11-24-2007 01:30 AM

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.

osor 11-24-2007 02:28 PM

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 (Post 2969082)
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.

ciden 11-26-2007 09:25 AM

Thank you very much. Will try it ASAP.
I have examinations going on, and they are not about computers.
I am Microbiology.

clark_kent 12-18-2007 02:06 AM

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.

blahdeblah 01-03-2009 11:02 AM

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


AntonyDeepak 12-13-2011 07:17 PM

CNTL + ALT + D works to 'Show desktop' in my computer.

neoh4x0r 09-09-2012 02:36 PM

Quote:

Originally Posted by AntonyDeepak (Post 4549258)
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 (Post 2994334)
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)

jerome1872000 09-17-2017 10:03 PM

Quote:

Originally Posted by ciden (Post 2965459)
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..

ondoho 09-18-2017 01:58 AM

Quote:

Originally Posted by jerome1872000 (Post 5759922)
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.


All times are GMT -5. The time now is 03:01 AM.