This question already has an answer here:
I want to create an application in Ubuntu which should run in the background. It needs to be informed when the focused 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. Please, help me.