Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Not sure if this is an appropriate question for this site, since it's not really specific to Ubuntu. Those who feel it isn't should probably respond to my crosspost on the Unix and Linux stackexchange site. Sorry for any confusion, I'm still negotiating the borderlines between these sites (and superuser.com, where I also crossposted). I guess we all are.

I make heavy use of workspaces, and have a lot of them (a 6x4 grid). I usually run openbox, but am currently using a machine that doesn't have openbox set up, so I'm using xfce because it's already mostly configured to my liking. I've gotten used to getting visual feedback when I switch workspaces, showing me which one I've just moved to, and am finding myself a bit disoriented in xfce. In openbox this is a big heads-up display, which is pretty much ideal. I'm aware that the workspace switcher panel applet will highlight the active workspace, but this only seems to work for workspaces which have some desktop space showing; since I generally have all my windows maximized, this isn't super helpful.

Is there a way to enable visual feedback showing the new workspace when switching workspaces in xfce?

share|improve this question
    
Update to others who miss metacity behaviour, see: bugzilla.xfce.org/show_bug.cgi?id=10276 –  jonasfj Dec 21 '13 at 8:07
add comment

7 Answers 7

I wrote a small code that shows a notification on workspace switch action. This code requires libnotify and libwnck

To compile it use the command:

gcc -O2 -o wsnd `pkg-config  --cflags --libs libnotify --libs libwnck` wsn.c

If you found compiling errors with above command, try this one:

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wsnd `pkg-config  --cflags --libs libnotify --libs libwnck-1.0` wsn.c

To test it from a terminal: ./wsnd

Include it as XFCE startup application: In XFCE you need to add it as startup applicaion on settings-manager->session and startup -> Application Autostart

The code:

//////////////////////////////////////////////////////////////////////////////////////
// Workspace Switch Notifier                                                        //
// Shows a OSD with workspace name on workspace switching action                    //
//                                                                                  //
// wsn.c -                                                                          //
//                                                                                  //
// Authors:                                                                         //
//    Isaac Maia Pessoa                                                             //
//                                                                                  //
// This program is free software: you can redistribute it and/or modify it          //
// under the terms of the GNU General Public License version 3, as published        //
// by the Free Software Foundation.                                                 //
//                                                                                  //
// This program is distributed in the hope that it will be useful, but              //
// WITHOUT ANY WARRANTY; without even the implied warranties of                     //
// MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR               //
// PURPOSE.  See the GNU General Public License for more details.                   //
//                                                                                  //
// You should have received a copy of the GNU General Public License along          //
// with this program.  If not, see <http://www.gnu.org/licenses/>.                  //
//////////////////////////////////////////////////////////////////////////////////////

#include <libnotify/notify.h>
#include <libwnck/libwnck.h>

#define N_SUMMARY "Workspace Changed"
#define N_ICON    "dialog-information"
#define N_APPNAME "workspace switch notifier"
#define N_TIMEOUT 2000 /*2000ms = 2s */

static NotifyNotification * m_notification = NULL;

static void
on_active_workspace_changed (WnckScreen    *screen,
                             WnckWorkspace *space,
                             gpointer      data)
{

  WnckWorkspace * active_workspace = wnck_screen_get_active_workspace(screen);
  const char * w_name = wnck_workspace_get_name (active_workspace);

  notify_notification_update(m_notification, N_SUMMARY, w_name, N_ICON);
  notify_notification_show(m_notification, NULL);
}

int main(int argc, char ** argv)
{

   GMainLoop *loop;   
   WnckScreen *screen;

   if (notify_init(N_APPNAME))
       m_notification = notify_notification_new(N_SUMMARY, "" , N_ICON);
   else
       fprintf(stderr, "Failed to init notifications\n");
   notify_notification_set_timeout(m_notification, N_TIMEOUT);

   gdk_init (&argc, &argv);

   loop = g_main_loop_new (NULL, FALSE);
   screen = wnck_screen_get_default();

   g_signal_connect (screen, "active-workspace-changed",
                    G_CALLBACK (on_active_workspace_changed), NULL);

   g_main_loop_run (loop);

   g_main_loop_unref (loop);    

   return 0;
}
share|improve this answer
    
Cool! I don't use xfce any more, so I don't think I'll have time to test this out. If somebody else can confirm that it works, though (it does look like it should, based on my limited knowledge of gtk code), I'll accept this answer. I think in practice it would take a bit of getting used to, because it's giving the workspace name rather than displaying its position in a grid image. But after a year and a half, it doesn't look like anything more ideal is going to come along :) Maybe the xubuntu maintainers could help you get this into the repository, if you're interested. –  intuited Aug 3 '12 at 12:42
    
Yes this is absolutely functional. On Arch I seem to have libwnck-3.0 so I bumped the version number a little in the second command. –  pestaa Oct 24 '13 at 8:37
    
Works great! Just changed the icon and the text. Thanks! –  Victor Dec 3 '13 at 10:32
add comment

You could install conky

save this to a file...

# Static and Variable Values used by Habitual/John Jones

# Static Values
own_window yes
own_window_transparent yes
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
use_xft yes
draw_outline no
draw_borders no
uppercase no
draw_shades no
draw_shades yes
double_buffer yes
border_width 0
text_buffer_size 2048
default_color white
update_interval 1.0

# Variable Values # These values are the ONLY thing that change from widget to widget
alignment bm
gap_x 5
gap_y 44
minimum_size 50 1
maximum_width 100

TEXT
${desktop_number}

run it in Xfce. (terminal) -> with conky -c /path/to/file &

icon/launcher conky -c /path/to/file

Everytime you switch desktops, the number of the desktop will be on the screen.

the "alignment bm" value controls desktop placement. bm is bottom-middle.

See http://conky.sourceforge.net/docs.html for DOCs.

share|improve this answer
    
Hmm. I might be doing something wrong. I'm seeing a number at the bottom of the screen, but a) it's always 24 (the number of desktops I have); b) it only shows up if that part of the desktop is not covered by a window. I'd like it to pop up, nice and big (taking up about 1/4 of the total screen space), on top of whatever's already being displayed, and then fade out after about a second. –  intuited Dec 4 '10 at 14:34
add comment

The only thing I can think of is to use separate wallpapers (I believe this is possible, but I cannot confirm as I don't use xfce every day) for each desktop. If you don't mind using compiz, you can configure it work much like xfwm, and installing the workspace namer plugin, which allows you to have names for each workspace displayed when you switch.

share|improve this answer
    
Hmm.. I'm hoping to avoid using compiz, since I'm running a relatively ancient laptop, but this is good to know. –  intuited Jan 6 '11 at 18:35
add comment

I have made a slight modification to the conky script above

It will allow for transparency for the numbers under XFCE and also you can modify the font size. It also uses the correct variable to display the workspace identity

# Static and Variable Values used by Habitual/John Jones
# Added to by AMH to add transparency under newer XFCE, the gothic font
# for sizing and changed the desktop variable to display the workspace
# correctly

# Static Values
own_window yes
own_window_transparent yes
own_window_type desktop
# Added to allow transparency in XFCE
own_window_argb_visual yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
use_xft yes
draw_outline no
draw_borders no
uppercase no
draw_shades no
draw_shades yes
double_buffer yes
border_width 0
text_buffer_size 2048
default_color white
update_interval 1.0

# Variable Values # These values are the ONLY thing that change from widget to widget
alignment bm
gap_x 5
gap_y 44
minimum_size 50 1
maximum_width 100

TEXT
${color light blue}${font URW Gothic L:size=60}${desktop}
share|improve this answer
add comment

I've modified Isaac Pessoa's answer for my own preferences. Instead of showing a notification on workspace changed, this briefly shows a hidden Xfce panel with the workspace switcher widget.

Here's what it looks like while switching workspaces: example

Save this file as wschanged.c:

#include <libwnck/libwnck.h>
#include <stdlib.h>

static void
on_active_workspace_changed (WnckScreen    *screen,
                             WnckWorkspace *space,
                             gpointer      data)
{
    // Executes a script on workspace change
    system ("~/.workspace-changed");
}

int main(int argc, char ** argv)
{

   GMainLoop *loop;   
   WnckScreen *screen;

   gdk_init (&argc, &argv);

   loop = g_main_loop_new (NULL, FALSE);
   screen = wnck_screen_get_default();

   g_signal_connect (screen, "active-workspace-changed",
                    G_CALLBACK (on_active_workspace_changed), NULL);

   g_main_loop_run (loop);
   g_main_loop_unref (loop);    

   return 0;
}

Now create a new Xfce panel anywhere on the edge of your screen and set it to auto-hide. Add the workspace switcher widget. Make a note of the panel number as displayed in the drop-down menu of the panel preferences window.

Make a .workspace-changed file in your home directory, replacing < P_NUMBER > with the panel number that you just created. Make sure this file is executable! (chmod +x .workspace-changed)

#!/bin/sh

# Show the auto-hidden workspace panel for a moment, then set it to autohide again
xfconf-query -c xfce4-panel -p /panels/panel-<P_NUMBER>/autohide -t bool -s false
xfconf-query -c xfce4-panel -p /panels/panel-<P_NUMBER>/autohide -t bool -s true

Now compile with:

gcc -O2 -DWNCK_I_KNOW_THIS_IS_UNSTABLE -o wschanged `pkg-config  --cflags --libs libwnck-1.0` wschanged.c

Test it in your terminal (./wschanged) to make sure everything looks right. When satisfied, add the program as an Xfce startup application: Settings -> Session and Startup -> Application Autostart.

share|improve this answer
add comment

This is exactly what I was looking for. Thank you, Isaac Pessoa and zspotter! I'm using Xfce on Arch, and in the spirit of keeping it minimal, I didn't want to resort to installing Compiz.

I'm not sure if this would or has happened to anyone else, but I noticed something pretty strange: The panel I set up to be the workspace indicator was configured to show 3 rows (I have 9 desktops). It was set to be about the same size as what you'd get in Ubuntu (about 3x6 inches). However, it would only show one row until I right-clicked the panel and selected properties (which, to be clear, was to display the properties window of the workspace-switcher). The fix was to remove the workspace-switcher that was on another panel.

Also, in order to change how long the workspace-indicator panel displays before it autohides again, you'll need to add this to your .gtkrc-2.0 file:

    style "xfce-panel-window-style"
{
  # Time in miliseconds before the panel will unhide on an enter event
  XfcePanelWindow::popup-delay = 225

  # Time in miliseconds before the panel will hide on a leave event
  XfcePanelWindow::popdown-delay = 350

  # Size of autohide window in pixels
  XfcePanelWindow::autohide-size = 3
}
class "XfcePanelWindow" style "xfce-panel-window-style"

Found here

In my case, since I'm on Arch, the gtkrc-2.0 file doesn't exist. I had to add that to the gtkrc file in my ~/.themes/[theme name here] directory.

Change the popup-delay and popdown-delay to your liking. For some strange reason, I had to set the values at about half of what I wanted them to be. Probably has something to do with wschanged executing the script.

If you want to place a panel in the middle of your screen showing a grid of workspaces, (similar to Ubuntu) you'll need to set that panel's alpha (under the appearance tab in the panel preferences) all the way down. That way you won't see a small bar on top of all your windows. Setting the autohide-size value to 1 will make it almost impossible for that panel to show by accident.

One last thing: if the cursor happens to be on top of the panel when you're switching workspaces, it will randomly show a tool tip and I have to move the cursor off of the panel to get it to hide again. Not a big deal though.

EDIT: I used zspotter's fix for this.

EDIT: I just noticed that scrolling the mouse while focused on the desktop will switch workspaces (using zspotter's fix). Nice!

EDIT: This causes my notification popus (i.e. when using volume keys, etc.) to appear in the wrong place. Specifically, when using the options top-left or top-right, the notifications appear in middle-left or middle-right. I don't have osd-notify installed -- just xfce4-notifyd. Everything in settings appeared to be correct. When I removed the panel and took wschanged off the applications auto-start list, problem was corrected..

share|improve this answer
add comment

I have this little python3 code-blob that reacts to workspace switching.

It's not made to display a notification, but to work around a chromium redraw bug. Anything you want to happen on workspace switch, you can easily throw in to the "fire_the_kludge" function though.

https://github.com/aking1012/chromiumKludge/blob/master/kludge.py

Here's a reworked example that uses libnotify2 to tell you your workspace:

#!/usr/bin/env python3

from gi.repository import Wnck, Gtk, Notify
import signal, time

class Kludge:
    def __init__(self):
        self.first = True
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        self.screen = Wnck.Screen.get_default()
        Notify.init("Workspace Switch Notifier")

    def fire_the_kludge(self, data_a, data_b):
        time.sleep(.1)
        try:
            workspace_num = str(self.screen.get_active_workspace().get_number())
        except:
            workspace_num = "Some error happened"
        popup = Notify.Notification.new("Workspace: " + workspace_num)
        popup.show()
        time.sleep(1)
        popup.close()

    def main(self):
        self.screen.connect("active-workspace-changed", self.fire_the_kludge)
        Gtk.main()

if __name__ == '__main__':
    print("Here comes the kludge")
    kludge = Kludge()
    kludge.main()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.