ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm brushing up on my C by learning some GTK and I'm trying to find a way to invert foreground and background colours on a particular widget of mine (EventBox + Label). I thought an easy way of doing this would be to get the current fg/bg colours and swap them around. I know how to SET colours using gtk_widget_modify_bg () and gtk_widget_modify_fg () but I don't know how to determine what colours are being used by default so that I can supply the reverse to the gtk_widget_modify_* functions.
If anyone knows how to do this or thinks that there is a better way to achieve what I'm trying to do, I'd like to hear from you.
I've been looking at Gtk myself so pretty much a novice in it but I had a look at the docs and managed to swap the colours using the widgets styles. Do know if this is the best way but it's one way. This is the callback function I used:
Thanks. That worked, but not without some possible dodginess. You see, my app is hidden by default and only appears when you click the systray icon (it's a calendar app). So, before I can extract the appropriate styles, I need to quickly call gtk_widget_show () followed by gtk_widget_hide () for GTK to "refresh" it's memory about what the current theme actually is. If I don't do this I get fg = black and bg = white always. My default theme is a dark background with light text so it's really apparent when GTK gets it wrong.
Do you have any experience with this? Is what I've done acceptable? It works, that much is clear, but I'm not sure if there isn't a cleaner, more efficient way of doing this or if there may be unintended consequences in doing things this way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.