Xfce Forum

Sub domains
 

You are not logged in.

#1 2014-10-27 14:28:48

ybznek
Member
Registered: 2013-05-07
Posts: 3

Event on workspace change

Hi,
Is there any way to run script after workspace change?
I want to suspend processes on some workspace, but I cannot hook this event.
I was looking for event in dbus, but I didn't see any workspace event.

Offline

#2 2014-10-27 15:14:15

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: Event on workspace change

I don't believe that there is a built-in method that you can hook into. However, you can write your own script that watches for workspace changes then perform whatever actions you require. For example, something like (wmctrl required):

#!/bin/bash
CURRENT_WORKSPACE=$(wmctrl -d | grep \* | cut -d' ' -f1)
while true
do
   sleep 1
   NEW_WORKSPACE=$(wmctrl -d | grep \* | cut -d' ' -f1)
   if [ $CURRENT_WORKSPACE -ne $NEW_WORKSPACE ]; then 
      echo "A workspace change has occurred. $CURRENT_WORKSPACE -> $NEW_WORKSPACE"
      CURRENT_WORKSPACE=$NEW_WORKSPACE
   fi
done

Since the inadvertant running of multiple instances of a script like this will cause you trouble, I like adding a file locking mechanism to scripts of this kind so that only one instance runs. It would look like this:

#!/bin/bash

# make sure that only one instance of this script is running per user
lockfile=/tmp/.wchg.$USER.lockfile
if ( set -o noclobber; echo "locked" > "$lockfile") 2> /dev/null; then
   trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT
   echo "wsp_notifyDEBUG: Locking succeeded" >&2

   CURRENT_WORKSPACE=$(wmctrl -d | grep \* | cut -d' ' -f1)
   while true
   do
      sleep 1
      NEW_WORKSPACE=$(wmctrl -d | grep \* | cut -d' ' -f1)
      if [ $CURRENT_WORKSPACE -ne $NEW_WORKSPACE ]; then 
         echo "A workspace change has occurred. $CURRENT_WORKSPACE -> $NEW_WORKSPACE"
         CURRENT_WORKSPACE=$NEW_WORKSPACE
      fi
   done

# can't create lockfile - notify user and quit
else
   echo "wsp_notifyDEBUG: Lock failed, check for existing process and/or lock file and delete - exiting." >&2
   exit 1
fi			

exit 0

CURRENT_WORKSPACE is the workspace that you are moving from and NEW_WORKSPACE is the workspace that you are moving to. Add your code in the block with the echo "A workspace has changed" command.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.010 seconds, 8 queries executed - Memory usage: 524.07 KiB (Peak: 524.91 KiB) ]