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;
}
If you're using Compiz (run wmctrl -m
if not sure), wmctrl only sees 1 desktop (2nd field of wmctrl -l, ie 0) but you can use the geometry (-G) option to know what window is on what virtual desktop. All windows in your current desktop will have an x-position between 0 and your screen's width. Same for the y-position between 0 and your screen's height.
So you can use something like that
#!/bin/bash
SCREEN_W=$(xwininfo -root | sed -n 's/^ Width: \(.*\)$/\1/p')
SCREEN_H=$(xwininfo -root | sed -n 's/^ Height: \(.*\)$/\1/p')
NAME='Navigator.Firefox'
wmctrl -xlG | awk -v W="$SCREEN_W" -v H="$SCREEN_H" -v NAME="$NAME" '$7==NAME && $3>=0 && $3<W && $4>=0 && $4<H {print $1}' | while read WINS; do wmctrl -ia "$WINS"; done
exit 0
You can hardcode your screen's width and height if you will, and NAME if you want a one-liner.
Im not sure how you want to handle multiple windows matching NAME. That will focus them all.
For metacity, desktop number of windows can be found using wmctrl -l
and grepping the 2nd field.
Best Answer
I'm not sure about Unity or XFCE, but fully customizable desktop switching is one of the many reasons I choose to run KDE (Kubuntu).
In KDE to limit task switching to the current screen do the following:
Press Alt+F2 and type
task switcher
and then select Task Switcher from the drop-down list.Inside the
task switcher
control panel's main tab there is a section called Filter windows by.Select the check box for
Virtual Desktops
,Activities
, andScreens
, and select theCurrent activity
option for each.Press
Apply
, and verify things work as expected before closing.Note: You can also find "Task Switcher" by doing the following:
click on the
Kick Off
menu-- Navigate to the
Computer
tabclick on the
System Settings
menu-- Under the
Workspace Appearance and Behavior
section chooseWindow Behavior
Related: What is a activity in KDE and what can I do with it?