ssokolow / quicktile

Adds window-tiling hotkeys to any X11 desktop. (An analogue to WinSplit Revolution for people who don't want to use Compiz Grid)
https://ssokolow.com/quicktile/
GNU General Public License v2.0
869 stars 78 forks source link

Add Gtk.init to make it work on openSUSE Leap 15.2 #127

Closed fiete201 closed 1 year ago

fiete201 commented 3 years ago

Just faced an issue on openSUSE Leap 15.2 where quicktile told me that it can't connect to X.

libgobject-2_0-0 in Version 2.62.6-lp152.2.6.1
libgtk-3-0 in Version 3.24.20-lp152.2.3.1
python3 in Version 3.6.12-lp152.4.17.1

After I did this change it worked. Seems that with the versions on my openSUSE tumbleweed work without the explicit init. (The change does no harm on my tumbleweed machine so it may work for everyone?)

libgobject-2_0-0 in Version 2.68.1-1.1
libgtk-3-0 in Version 3.24.29-1.1
python38 in Version 3.8.10-1.1

Hope that this might help somehow.

Cheers fiete

ssokolow commented 3 years ago

Thanks for letting me know.

Given that the docs say "Note that calling any GTK function or instantiating any GTK type after this function returns False results in undefined behavior", it'd be better to do something like this just before the app = line:

# Work around a "the Gtk.Application ::startup handler does it for you" bug
if not Gtk.init_check():
    raise XInitError("Gtk failed to connect to the X server. Cannot start.")

(Just before the app = line so the "failed to connect to X11" error messages I was able to be more specific about have a chance first.)

fiete201 commented 3 years ago

At that point it is too late since we need the Gtk init before we instantiate WindowManager since the error itself is thrown there.

Sorry if I use some wrong naming I'm new to python programming to be honest and just tried to get it working with some googling around :-D

ssokolow commented 3 years ago

At that point it is too late since we need the Gtk init before we instantiate WindowManager since the error itself is thrown there.

That's fine. I'd just like to have it...

  1. After the attempt to initialize XDisplay since that's the one with the detailed error message and the narrow scope of what could go wrong.
  2. Check if Gtk.init_check() returns False and raise an XInitError so it won't try to make calls into GTK after a failure.

Sorry if I use some wrong naming I'm new to python programming to be honest and just tried to get it working with some googling around :-D

No problem. Jargon doesn't have to be perfect as long as you're making a good-faith effort.

fiete201 commented 3 years ago

Hope that it is fine now :-)

ssokolow commented 3 years ago

*chuckle* Yeah, that looks good.

I'm at the end of my day now, but I'll try to get it tested and merged tomorrow.

(And fix that gtkexcepthook.py MyPy failure on Travis while I'm at it.)

ssokolow commented 3 years ago

OK, works fine here.

I realized that I forgot to actually unit-test having an invalid DISPLAY environment variable value and the error handling doesn't work as expected, but that's not a problem with your contribution... just something I need to fix when I have time to work on QuickTile again.

Also, I realized that there's something I forgot to ask. Could you please add yourself to docs/authors/index.rst and then run docs/update_authors.sh to regenerate the AUTHORS file in the root of the repo?

(Looks like I forgot to mention that in CONTRIBUTING.rst since it's only mentioned in the developer's guide at docs/developing.rst.)

ssokolow commented 3 years ago

Given how it seems kind of unfair to keep going back and forth like this over a little hobby project, I could pull your branch, correct it myself, and then merge it manually if you'd prefer that, but there are three issues with your authors text:

  1. "with a bit older library versions" isn't quite grammatically correct English. (I haven't exhaustively confirmed, but my intuition is saying that you can't use an article (a/an) as part of an adverb when it's being used to modify a prefix adjective. "slightly older library versions" or "library versions that are a bit older" would work.)
  2. "A bit older" isn't the problem. I'm on Kubuntu 20.04 LTS, which has GTK 3.24.20-0ubuntu1, and the code you're patching was developed on Kubuntu 16.04, on GTK 3.18.9-1ubuntu3.
  3. I prefer to keep reStructuredText word-wrapped to 80 columns and to at least use <code> styling for mentions of modules and other language constructs.

If you have Sphinx set up so you can run make html in the docs directly and check that my memory of those finicky cross-reference links is correct, this would probably be best:

`Fritz Reichwald`_
    Added :func:`Gtk.init_check` to :mod:`quicktile.__main__` to work around a 
    bug in some builds of GTK.

If not, I'll accept ordinary code literals.

`Fritz Reichwald`_
    Added ``Gtk.init_check`` to ``__main__.py`` to work around a bug in some 
    builds of GTK.
fiete201 commented 3 years ago

Thanks for your suggestion! I tried to incorporate that but the first suggestion generated the following:

/home/fiete/freichw/proj/quicktile/docs/authors/index.rst:80: WARNING: py:mod reference target not found:
 quicktile.__main__ 

So I now pushed the second version :-)

Please tell me if I missed something else ;-)

ssokolow commented 3 years ago

I tried to incorporate that but the first suggestion generated the following:

Yeah. That's the "check that my memory of those finicky cross-reference links is correct" part. I know there exists a way to make that work, but I have to dig out my Sphinx cross-reference index inspector to figure out what it wants if I spend more than a day or two away from it.

Please tell me if I missed something else ;-)

Today isn't a good day, but I'll try to give it one more look-over within the next couple of days.

ssokolow commented 3 years ago

Sorry for not getting back to you. I'm normally nocturnal and they've been doing road work for the last few days, so I've been too tired to work on this. I'll get back to this as soon as I can think again.

ssokolow commented 1 year ago

Sorry for going silent. I hadn't realized that COVID's effects on society had me on a downward trajectory and pretty much everything I was doing in the sphere of hobby programming fell apart.