Giter Club home page Giter Club logo

Comments (8)

M4he avatar M4he commented on July 23, 2024 1

But even with the code shown below added, the example still registers each and every workspace change correctly while at the same time cortile frequently fails to do so. The root cause must be something else ...

...just a guess in the dark, please comment those 4 lines and report back: https://github.com/leukipp/cortile/blob/main/input/mousebinding.go#L50-L53

That's it! After commenting those lines I cannot reproduce the issue anymore.

from cortile.

leukipp avatar leukipp commented on July 23, 2024

Thanks for your efforts and detailed description, nailing the problem down:

I noticed that occasionally some events are never received by cortile at all, for example the _NET_CURRENT_DESKTOP property change from the root window when changing the workspace.

At first I thought it was about my picom config and all the stuff going on (fade animation, blur) that choked the X connection and event queue somehow but then I noticed it doesn't happen when changing the workspace via external means (wmctrl or the workspace switcher of the LXQt panel) instead of Openbox's keybindings.

This could be an upstream issue, that can only be fixed in the xgb or xgbutil library which cortile relies on.

Trying to reproduce this bug on an environment will cost me some time, so I would kindly ask you to run the minimal example below to confirm that this is caused by xgb dependencies.

minimal example

main.go

Please build via go build main.go and run the binary.

package main

import (
	"fmt"

	"github.com/BurntSushi/xgb/xproto"

	"github.com/BurntSushi/xgbutil"
	"github.com/BurntSushi/xgbutil/ewmh"
	"github.com/BurntSushi/xgbutil/xevent"
	"github.com/BurntSushi/xgbutil/xprop"
	"github.com/BurntSushi/xgbutil/xwindow"
)

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		fmt.Println("Connection to X server failed")
		return
	}

	root := xwindow.New(X, X.RootWin())
	root.Listen(xproto.EventMaskSubstructureNotify | xproto.EventMaskPropertyChange)

	fmt.Println("Listen")

	xevent.PropertyNotifyFun(StateUpdate).Connect(X, root.Id)
	xevent.Main(X)
}

func StateUpdate(X *xgbutil.XUtil, e xevent.PropertyNotifyEvent) {
	aname, err := xprop.AtomName(X, e.Atom)

	fmt.Println(aname)

	if err != nil {
		fmt.Println("Error retrieving atom name")
		return
	}

	if IsInList(aname, []string{"_NET_CURRENT_DESKTOP"}) {
		fmt.Println("--------- _NET_CURRENT_DESKTOP --------->", CurrentDesktopGet(X))
	}
}

func IsInList(item string, items []string) bool {
	for i := 0; i < len(items); i++ {
		if items[i] == item {
			return true
		}
	}
	return false
}

func CurrentDesktopGet(X *xgbutil.XUtil) uint {
	currentDesk, err := ewmh.CurrentDesktopGet(X)

	if err != nil {
		fmt.Println("Error retrieving current desktop")
	}

	return currentDesk
}

While trying to identify the problem I added more log output to cortile at places where X events are initially received and processed.

The minimal example should include the cortile implementations (root.go) you mentioned, where the issue original arises.

Please let me know, if the --------- _NET_CURRENT_DESKTOP ---------> output still reports the wrong (previous) workspace. It may be some race condition where _NET_CURRENT_DESKTOP fires, but ewmh.CurrentDesktopGet(X) still reports the old state.

from cortile.

M4he avatar M4he commented on July 23, 2024

Thanks for creating the minimal example! I tried it and running it at the same time as cortile, I cannot reproduce the issue in the minimal example whereas it keeps happening in cortile.

As a next step I added the code below to the example to include event listener callbacks for all clients/windows mimicking what cortile does. I thought that maybe having a lot of listeners to different X clients in a single program might be the reason for the issues.

But even with the code shown below added, the example still registers each and every workspace change correctly while at the same time cortile frequently fails to do so. The root cause must be something else ...

code patch for attaching client handlers in the minimal example
@@ -25,9 +25,42 @@ func main() {
fmt.Println("Listen")

xevent.PropertyNotifyFun(StateUpdate).Connect(X, root.Id)
+    windows, err := ewmh.ClientListStackingGet(X)
+    if err != nil {
+		fmt.Println("Error retrieving client list: ", err)
+	}
+    for _, win := range windows {
+        fmt.Println("attaching window handlers")
+        attachClientHandlers(X, xwindow.New(X, win))
+    }
xevent.Main(X)
}

+func attachClientHandlers(X *xgbutil.XUtil, c *xwindow.Window) {
+	c.Listen(xproto.EventMaskStructureNotify | xproto.EventMaskPropertyChange | xproto.EventMaskFocusChange)
+
+	// Attach structure events
+	xevent.ConfigureNotifyFun(func(x *xgbutil.XUtil, ev xevent.ConfigureNotifyEvent) {
+		fmt.Println("Client structure event")
+	}).Connect(X, c.Id)
+
+	// Attach property events
+	xevent.PropertyNotifyFun(func(x *xgbutil.XUtil, ev xevent.PropertyNotifyEvent) {
+		aname, _ := xprop.AtomName(X, ev.Atom)
+		fmt.Println("Client property event ", aname)
+	}).Connect(X, c.Id)
+
+	// Attach focus in events
+	xevent.FocusInFun(func(x *xgbutil.XUtil, ev xevent.FocusInEvent) {
+		fmt.Println("Client focus in event")
+	}).Connect(X, c.Id)
+
+	// Attach focus out events
+	xevent.FocusOutFun(func(x *xgbutil.XUtil, ev xevent.FocusOutEvent) {
+		fmt.Println("Client focus out event")
+	}).Connect(X, c.Id)
+}
+
func StateUpdate(X *xgbutil.XUtil, e xevent.PropertyNotifyEvent) {
aname, err := xprop.AtomName(X, e.Atom)

from cortile.

leukipp avatar leukipp commented on July 23, 2024

But even with the code shown below added, the example still registers each and every workspace change correctly while at the same time cortile frequently fails to do so. The root cause must be something else ...

...just a guess in the dark, please comment those 4 lines and report back:
https://github.com/leukipp/cortile/blob/main/input/mousebinding.go#L50-L53

from cortile.

leukipp avatar leukipp commented on July 23, 2024

Please also try the version from the xgb-jezek branch, where github.com/BurntSushi/xgb* is replaced with the github.com/jezek/xgb* fork, which provides those features:

I've forked the XGB repository from BurntSushi's github to apply some
patches which caused panics and memory leaks upon close and tests were added,
to test multiple server close scenarios.

Much of the code has been rewritten in an effort to support thread safety and multiple extensions.

It is thread safe and gets immediate improvement from parallelism when
GOMAXPROCS > 1. (See the benchmarks in xproto/xproto_test.go for evidence.)

from cortile.

M4he avatar M4he commented on July 23, 2024

Please also try the version from the xgb-jezek branch [...]

No difference to the main branch's behavior in terms of the issue observed.

from cortile.

leukipp avatar leukipp commented on July 23, 2024

Thanks for your feedback! A proper fix will be included in the next cortile release.

from cortile.

leukipp avatar leukipp commented on July 23, 2024

The fix is included in v2.5.0.

from cortile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.