[SOLVED] How do you detect when the active app or window changes with GTK+ in C?

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
otacon14112

[SOLVED] How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 »

I'm studying GTK+, and I'm trying to find out a way for my program to know every time a window or application becomes the new active one, or gains focus. For example, I'm trying to learn how to write a global menu bar. I want it to behave similarly to Mac OS, so for example, when you click on another window, if it's a different application, you're presented with different menu options. But first I need to figure out a way to let my program get notified every time a window becomes the active window.

I read that in Xlib, you can set a flag for substructure redirection but that totally intercepts a signal, and the window that wants to be remapped won't be, because whatever program requested the notification will get the command from the window manager instead. But I'm wanting to use GTK+. I don't want to prevent an app or window from being remapped, raised, or gain the focus; I just want to know when it happens, and the window ID atom of the window, so that I can find out more information about that window.

Is it possible in GTK+?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
JosephM
Level 6
Level 6
Posts: 1463
Joined: Sun May 26, 2013 6:25 pm

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by JosephM »

What your talking about is normally the province of the window manager. What you might want to do is look at something like libwnck. It's what things like mate-panel use to get similar information for it's window list. It works with gtk and might give you a place to get started.

https://developer.gnome.org/libwnck/stable/
When I give opinions, they are my own. Not necessarily those of any other Linux Mint developer or the Linux Mint project as a whole.
otacon14112

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 »

Thanks
otacon14112

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 »

Unfortunately, libwnck is unstable. It's strange, because in the uri it says stable, but when I click on the relevant widgets on the link you sent me, they're all unstable. I went ahead anyway, and tried to make some sample programs to test it out, and it wouldn't even compile, giving me an error and refusing to compile it because it was unstable, and even went so far to suggest NOT using it.
otacon14112

Re: How do you detect when the active app or window changes with GTK+ in C?

Post by otacon14112 »

JosephM wrote:What your talking about is normally the province of the window manager. What you might want to do is look at something like libwnck. It's what things like mate-panel use to get similar information for it's window list. It works with gtk and might give you a place to get started.

https://developer.gnome.org/libwnck/stable/
I just found out that a preprocessor definition is needed in order for it to compile, so now it appears I can move forward. I want to thank you again.
Locked

Return to “Other topics”