This question already has an answer here:
I want to create one application in ubuntu which should run in the background. It needs to be informed when the focussed window changes. Basically I need to run a callback function in my application on window focus change event.
I have never programmed anything in ubuntu. I am not sure how to move ahead.