Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK3 Support #11

Closed
swt2c opened this issue Jul 15, 2021 · 7 comments
Closed

GTK3 Support #11

swt2c opened this issue Jul 15, 2021 · 7 comments

Comments

@swt2c
Copy link
Contributor

swt2c commented Jul 15, 2021

GTK3 support would be appreciated. The main issue seems to be that GdkPixmap is gone, so I wasn't sure how to replace gdk_pixmap_foreign_new().

@onli
Copy link
Owner

onli commented Jul 15, 2021

Maybe we can take inspiration from wnck here? wxBitmap says this:

wxGTK supports any file supported by gdk-pixbuf;

So maybe we just have to find a different approach to transform the X background Pixmap to that. If I understand the hints from https://developer.gnome.org/gdk2/stable/gdk2-Bitmaps-and-Pixmaps.html#gdk-pixmap-new right we need to use Cairo now:

gdk_pixmap_create_from_xpm has been deprecated since version 2.22 and should not be used in newly-written code.

Use a GdkPixbuf instead. You can use gdk_pixbuf_new_from_file() to create it. If you must use a pixmap, use gdk_pixmap_new() to create it and Cairo to draw the pixbuf onto it. [highlight by me]

https://github.com/lanoxx/libwnck/blob/bcfa20a542693b3baadf797795efbcb7c3afb423/libwnck/xutils.c#L1689-L1709 does about that:

GdkPixbuf*
_wnck_gdk_pixbuf_get_from_pixmap (Screen *screen,
                                  Pixmap  xpixmap)
{
  cairo_surface_t *surface;
  GdkPixbuf *retval;

  surface = _wnck_cairo_surface_get_from_pixmap (screen, xpixmap);

  if (surface == NULL)
    return NULL;

  retval = gdk_pixbuf_get_from_surface (surface,
                                        0,
                                        0,
                                        cairo_xlib_surface_get_width (surface),
                                        cairo_xlib_surface_get_height (surface));
  cairo_surface_destroy (surface);

  return retval;
}

That we'd also have to copy _wnck_cairo_surface_get_from_pixmap from that same file is annoying though. And in general that change is a big code quality regression - all this bs just to replace one function -, but that seems to be expected with GTK 3.

https://developer.gnome.org/gtk3/stable/ch26s02.html#id-1.6.3.4.5 (or a different section of that guide) might give additional alternatives, maybe that wnck code is not optimal.

Hard stuff, documentation is minimal and code searches make it look as if simdock was the only program that ever used this code (which can't really be true).

Could you help with this work? I would basically just try to copy what I found now, and there might be better options.

@swt2c
Copy link
Contributor Author

swt2c commented Jul 15, 2021

Sure, I will look into it.

@onli onli added this to Ideas in Improvement Ideas Jul 18, 2021
@onli onli moved this from Ideas to Technical foundation in Improvement Ideas Jul 18, 2021
@onli
Copy link
Owner

onli commented Nov 25, 2023

This seems to have become a critical issue now. At least on my system, the GTK2 support libraries are gone. I had no luck in getting the GTK3 route to work though. @swt2c, did you succeed here?

This might be the end of the route for simdock otherwise.

@swt2c
Copy link
Contributor Author

swt2c commented Nov 25, 2023

No, I gave up. Admittedly, I don't use simdock - I was mainly interested in porting wxWidgets applications to GTK3 from a distribution perspective. We ended up just dropping simdock in Fedora, I believe.

@onli
Copy link
Owner

onli commented Nov 25, 2023

Ok, I understand :)

If someone else has an idea how to solve this, please speak up! I'll give this a bit of time and otherwise mark the project as broken.

@onli
Copy link
Owner

onli commented Dec 4, 2023

I managed to cobble a solution together.

The main commits are 9fa2956 and 0d32ab0. 9fa2956 moved the makefile to wxwidgets with GTK3 and contained the core logic to make the background detection work again. 0d32ab0 then moved the makefile to wnck-3.0, as wnck-1.0 relies on GTK2, which makes the binary not run. The commit also contains a correction: Instead of using the XID simdock gets before via wnck, this now uses a gdk helper function instead.

In summary, Instead of relying on wnck, it's using gdk functions now. The replacement for gdk_pixmap_foreign_new was gdk_pixbuf_get_from_window, which needs to get the root window as in this code:

gdk_x11_window_foreign_new_for_display(
    gdk_display_get_default(),
    gdk_x11_get_default_root_xwindow()
),

My function is then still using a wnck helper function to get the size of the display, as one needs that to define the area gdk_pixbuf_get_from_window works on. Probably an unnecessary use of wnck. The constructor of wxBitmap now works with the pixbuf we get from gdk_pixbuf_get_from_window.

My initial understanding of having to use cairo here seems to have been completely wrong. Edit: Or maybe not. The problem with the approach above is that it does not select the X background, but the whole X desktop with content like the painted window. To copy the old approach it would be necessary to somehow get the X background, but wnck's get_background_pixmap gives us only the XID of that background, and gdk_x11_window_foreign_new_for_display then complains that said XID is not the XID of a window (which might be correct, if I understand https://tronche.com/gui/x/xlib/window/attributes/background.html correctly). So maybe it would be necessary to use the cairo functions to somehow get the background pixmap, which is exactly what #11 (comment) seems to show.

For now I instead opted for a workaround via 8cadc12, to hide the app before the background is fetched.

@swt2c Thank for the bugreport here. If you have the time, it would be awesome if you could help me with the Readme - I'd love to have a section about the necessary requirements to get this to build on Fedora. The ones for Ubuntu are probably outdated (and Ubuntu seems to have dropped wnck? oO). I'll add a section for void myself now.

@onli
Copy link
Owner

onli commented Dec 4, 2023

The GTK3 migration was done, so I'll close here already.

@onli onli closed this as completed Dec 4, 2023
This was referenced Dec 4, 2023
@onli onli moved this from Technical foundation to Done in Improvement Ideas Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants