From 2a6cba9c3c2e3d2ea720099b61b39669ff6b7474 Mon Sep 17 00:00:00 2001 From: scrouthtv Date: Mon, 1 Mar 2021 18:28:23 +0100 Subject: Update main.go added example of reading events --- examples/create-window/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 50a9bff..284daef 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -96,12 +96,22 @@ func main() { fmt.Println("Both event and error are nil. Exiting...") return } - + if ev != nil { fmt.Printf("Event: %s\n", ev) } if xerr != nil { fmt.Printf("Error: %s\n", xerr) } + + // This is how accepting events work: + // The application checks what event we got + // (the event must be registered using either xproto.CreateWindow (see l.35) or + // xproto.ChangeWindowAttributes (see l.50)). + // and reacts to it accordingly. All events are defined in the xproto subpackage. + switch ev.(type) { + case xproto.DestroyNotifyEvent: + return // Exit if we get a DestroyNotifyEvent. + } } } -- cgit v1.2.3 From 4c1bf8cd8d4f0f96428a90f3117896c7f1564cdf Mon Sep 17 00:00:00 2001 From: Lenni Date: Wed, 3 Mar 2021 19:04:54 +0100 Subject: added listening to key presses --- examples/create-window/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 284daef..76df734 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -110,6 +110,16 @@ func main() { // xproto.ChangeWindowAttributes (see l.50)). // and reacts to it accordingly. All events are defined in the xproto subpackage. switch ev.(type) { + case xproto.KeyPressEvent: + // See https://pkg.go.dev/github.com/jezek/xgb@v0.0.0-20210121230032-cec22bda1ce1/xproto#KeyPressEvent + // for documentation about a key press event. + kpe := ev.(xproto.KeyPressEvent) + fmt.Printf("Key pressed: %d", kpe.Detail) + // The Detail value depends on the keyboard layout, + // for QWERTY, q is #24. + if kpe.Detail == 24 { + return // exit on q + } case xproto.DestroyNotifyEvent: return // Exit if we get a DestroyNotifyEvent. } -- cgit v1.2.3 From 2825966d27b67b6b0227bcbfcd81f3c995c0f472 Mon Sep 17 00:00:00 2001 From: Lenni Date: Wed, 3 Mar 2021 19:05:58 +0100 Subject: formatting --- examples/create-window/main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 76df734..d4f6d96 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -49,7 +49,8 @@ func main() { 0xffffffff, xproto.EventMaskStructureNotify | xproto.EventMaskKeyPress | - xproto.EventMaskKeyRelease}) + xproto.EventMaskKeyRelease, + }) // MapWindow makes the window we've created appear on the screen. // We demonstrated the use of a 'checked' request here. @@ -96,14 +97,14 @@ func main() { fmt.Println("Both event and error are nil. Exiting...") return } - + if ev != nil { fmt.Printf("Event: %s\n", ev) } if xerr != nil { fmt.Printf("Error: %s\n", xerr) } - + // This is how accepting events work: // The application checks what event we got // (the event must be registered using either xproto.CreateWindow (see l.35) or @@ -115,8 +116,8 @@ func main() { // for documentation about a key press event. kpe := ev.(xproto.KeyPressEvent) fmt.Printf("Key pressed: %d", kpe.Detail) - // The Detail value depends on the keyboard layout, - // for QWERTY, q is #24. + // The Detail value depends on the keyboard layout, + // for QWERTY, q is #24. if kpe.Detail == 24 { return // exit on q } -- cgit v1.2.3 From 89052459e19439240a5f3a1d3e267650f0d0c554 Mon Sep 17 00:00:00 2001 From: Lenni Date: Sat, 6 Mar 2021 17:46:57 +0100 Subject: Added explanation to the whole DestroyNotifyEvent thing. See https://github.com/jezek/xgb/pull/1 --- examples/create-window/main.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index d4f6d96..9510f9c 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -17,6 +17,7 @@ func main() { fmt.Println(err) return } + defer X.Close() // xproto.Setup retrieves the Setup information from the setup bytes // gathered during connection. @@ -122,7 +123,22 @@ func main() { return // exit on q } case xproto.DestroyNotifyEvent: - return // Exit if we get a DestroyNotifyEvent. + // Depending on the user's desktop environment (especially + // window manager), killing a window might close the + // client's X connection (e. g. the default Ubuntu + // desktop environment). + // + // If that's the case for your environment, closing this example's window + // will also call the underlying Go program (because closing the X + // connection gives a nil event and EOF error). + // + // Consider how a single application might have multiple windows + // (e.g. an open popup or dialog, ...) + // + // With other DEs, the X connection will still stay open even after the + // X window is closed. For these DEs (e.g. i3) we have to check whether + // the WM sent us a DestroyNotifyEvent and close our program: + return } } } -- cgit v1.2.3 From 35e3533c4edb11d08cc36fa9a524df38d7ab5f57 Mon Sep 17 00:00:00 2001 From: Lenni Date: Sat, 6 Mar 2021 17:47:38 +0100 Subject: formatting --- examples/create-window/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 9510f9c..ef7d98a 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -125,16 +125,16 @@ func main() { case xproto.DestroyNotifyEvent: // Depending on the user's desktop environment (especially // window manager), killing a window might close the - // client's X connection (e. g. the default Ubuntu + // client's X connection (e. g. the default Ubuntu // desktop environment). - // + // // If that's the case for your environment, closing this example's window // will also call the underlying Go program (because closing the X // connection gives a nil event and EOF error). - // + // // Consider how a single application might have multiple windows // (e.g. an open popup or dialog, ...) - // + // // With other DEs, the X connection will still stay open even after the // X window is closed. For these DEs (e.g. i3) we have to check whether // the WM sent us a DestroyNotifyEvent and close our program: -- cgit v1.2.3 From 257276cd70a8423fbe4283c6d7a6b99a0c3d23eb Mon Sep 17 00:00:00 2001 From: Lenni Date: Sun, 7 Mar 2021 09:23:33 +0100 Subject: minor fixes --- examples/create-window/main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index ef7d98a..9d1784c 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -113,7 +113,7 @@ func main() { // and reacts to it accordingly. All events are defined in the xproto subpackage. switch ev.(type) { case xproto.KeyPressEvent: - // See https://pkg.go.dev/github.com/jezek/xgb@v0.0.0-20210121230032-cec22bda1ce1/xproto#KeyPressEvent + // See https://pkg.go.dev/github.com/jezek/xgb/xproto#KeyPressEvent // for documentation about a key press event. kpe := ev.(xproto.KeyPressEvent) fmt.Printf("Key pressed: %d", kpe.Detail) @@ -129,7 +129,7 @@ func main() { // desktop environment). // // If that's the case for your environment, closing this example's window - // will also call the underlying Go program (because closing the X + // will also close the underlying Go program (because closing the X // connection gives a nil event and EOF error). // // Consider how a single application might have multiple windows @@ -137,7 +137,11 @@ func main() { // // With other DEs, the X connection will still stay open even after the // X window is closed. For these DEs (e.g. i3) we have to check whether - // the WM sent us a DestroyNotifyEvent and close our program: + // the WM sent us a DestroyNotifyEvent and close our program. + // + // For more information about closing windows while maintaining + // the X connection see + // https://github.com/jezek/xgbutil/blob/master/_examples/graceful-window-close/main.go return } } -- cgit v1.2.3 From c3652e28fc56c658e9011742567e52ee2f22ed98 Mon Sep 17 00:00:00 2001 From: Lenni Date: Sun, 7 Mar 2021 09:26:04 +0100 Subject: rephrased weird comment --- examples/create-window/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index 9d1784c..c096a91 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -107,10 +107,10 @@ func main() { } // This is how accepting events work: - // The application checks what event we got - // (the event must be registered using either xproto.CreateWindow (see l.35) or - // xproto.ChangeWindowAttributes (see l.50)). - // and reacts to it accordingly. All events are defined in the xproto subpackage. + // The application checks what event we got and reacts to it + // accordingly. All events are defined in the xproto subpackage. + // To receive events, we have to first register it using + // either xproto.CreateWindow or xproto.ChangeWindowAttributes. switch ev.(type) { case xproto.KeyPressEvent: // See https://pkg.go.dev/github.com/jezek/xgb/xproto#KeyPressEvent -- cgit v1.2.3 From 06eab223430e738079eb644911256671a319980e Mon Sep 17 00:00:00 2001 From: jEzEk Date: Sun, 7 Mar 2021 15:13:16 +0100 Subject: Add missing "\n" at the end of fmt.Printf --- examples/create-window/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/create-window/main.go') diff --git a/examples/create-window/main.go b/examples/create-window/main.go index c096a91..a637d0e 100644 --- a/examples/create-window/main.go +++ b/examples/create-window/main.go @@ -116,7 +116,7 @@ func main() { // See https://pkg.go.dev/github.com/jezek/xgb/xproto#KeyPressEvent // for documentation about a key press event. kpe := ev.(xproto.KeyPressEvent) - fmt.Printf("Key pressed: %d", kpe.Detail) + fmt.Printf("Key pressed: %d\n", kpe.Detail) // The Detail value depends on the keyboard layout, // for QWERTY, q is #24. if kpe.Detail == 24 { -- cgit v1.2.3