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;
}
Best Answer
If we limit the setup to have a different set of launchers per desktop it is not very complicated. What we need is a script, running in the background to keep track of the current workspace and automatically alter the set of launchers accordingly.
1. A set of launchers per workspace
Let's say I have four workspaces, I want the following launchers to be available on the different workspaces:
workspace 1 > workspace 2 > workspace 3 > workspace 4 >
How to set up
The script uses
wmctrl
:In your home directory (not in a subdirectory, but on the "first" level), create a directory (exactly) named:
inside this directory, create for each of your desktops, a folder named (exactly):
Create launchers for all applications (for all workspaces) on your desktop and copy them to the corresponding folders.
Copy the script below into an empty file, save it as
change_launchers.py
. Test-run it by running in a terminal window the command:If all works fine, add it to your startup applications
The script
Note
In different localized versions of Ubuntu, the name of the "Desktop" folder may differ (In Dutch: "Bureaublad"). If in your Ubuntu version the name of the desktop folder is not "Desktop", change it in the line:
2. Extending possibilities, launchers and links
If we add a few lines to the script, the setting-per-workspace options can be extended with a altering set of links to directories:
On one workspace we have a e.g. a link to the Documents folder, combined with launchers of office applications:
On another workspace we have a link to the Pictures folder, combined with launchers of Image editors:
How to setup
The setup is pretty much the same as in option 1, but additionally, in the data folders (see option 1), create links to folders (using
ln -s <source> <destination>
) you'd like to be available on the corresponding workspace:The script