Hi Shruikan,
I have never have this need, but I got intiged with your question, so I'll toss an idea:
After a quick search on the web I found this dbus-monitor command that seems to "catch" the session states
Code:
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'"
I have not hte possibility to test it right but seems that this returns a boolean value so it should be possible to catch that value and operate based on it
So my idea is that you put that in a script that runs on the background and see what is returned when you lock/unlock the screen then use the different states trigger whatever you need to do.
Let us know if you get this working, is interesting
HTH