Skip to content
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Xlib Binding

[![GoDoc](https://godoc.org/github.com/vbsw/xlib?status.svg)](https://godoc.org/github.com/vbsw/xlib)
[![GoDoc](https://godoc.org/github.com/vbsw/xlib?status.svg)](https://godoc.org/github.com/daviseidel/xlib)

## About
Xlib Binding is a binding of Xlib (version 11, release 6.7) for the programming language Go.

Xlib Binding is published at <https://github.com/vbsw/xlib>.
This is a more complete fork of the one by vbsw: <https://github.com/vbsw/xlib>.

## Copyright
Copyright 2023 Davi Seidel (daviseidel.brandao@gmail.com)

Copyright 2016 Vitali Baumtrok (vbsw@mailbox.org)

Xlib Binding is distributed under the terms of the Boost Software License, version 1.0.
Expand Down
127 changes: 88 additions & 39 deletions events.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@

// Copyright 2016 Vitali Baumtrok
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)


// Binding of Xlib (version 11, release 6.7).
package xlib


// #cgo LDFLAGS: -lX11
// #include <stdlib.h>
// #include <X11/Xlib.h>
// #include "xlib.h"
import "C"
import (
//"unsafe"
)


const (
Expose = int(C.Expose)
Expand All @@ -26,6 +19,7 @@ const (
)

const (
// All Event masks.
NoEventMask = int64(C.NoEventMask)
KeyPressMask = int64(C.KeyPressMask)
KeyReleaseMask = int64(C.KeyReleaseMask)
Expand All @@ -52,6 +46,39 @@ const (
PropertyChangeMask = int64(C.PropertyChangeMask)
ColormapChangeMask = int64(C.ColormapChangeMask)
OwnerGrabButtonMask = int64(C.OwnerGrabButtonMask)
GrabModeSync = int(C.GrabModeSync)
GrabModeAsync = int(C.GrabModeAsync)
Mod1Mask = int(C.Mod1Mask)
Mod2Mask = int(C.Mod2Mask)
Mod3Mask = int(C.Mod3Mask)
Mod4Mask = int(C.Mod4Mask)
Mod5Mask = int(C.Mod5Mask)
ShiftMask = int(C.ShiftMask)
LockMask = int(C.LockMask)
ControlMask = int(C.ControlMask)
AnyModifier = int(C.AnyModifier)
Button1Mask = int(C.Button1Mask)
Button2Mask = int(C.Button2Mask)
Button3Mask = int(C.Button3Mask)
Button4Mask = int(C.Button4Mask)
Button5Mask = int(C.Button5Mask)
ShiftMapIndex = int(C.ShiftMapIndex)
LockMapIndex = int(C.LockMapIndex)
ControlMapIndex = int(C.ControlMapIndex)
Mod1MapIndex = int(C.Mod1MapIndex)
Mod2MapIndex = int(C.Mod2MapIndex)
Mod3MapIndex = int(C.Mod3MapIndex)
Mod4MapIndex = int(C.Mod4MapIndex)
Mod5MapIndex = int(C.Mod5MapIndex)
PointerWindow = int(C.PointerWindow)
InputFocus = int(C.InputFocus)
PointerRoot = int(C.PointerRoot)
AnyPropertyType = int(C.AnyPropertyType)
AnyKey = int(C.AnyKey)
AnyButton = int(C.AnyButton)
AllTemporary = int(C.AllTemporary)
CurrentTime = int(C.CurrentTime)
NoSymbol = int(C.NoSymbol)
)

type XEvent interface {
Expand All @@ -64,53 +91,75 @@ type tEventType struct {

type XKeyEvent struct {
tEventType
Serial uint64
SendEvent bool
Display *Display
Window Window
Root Window
Subwindow Window
Time uint64
X, Y int
Serial uint64
SendEvent bool
Display *Display
Window Window
Root Window
Subwindow Window
Time uint64
X, Y int
XRoot, YRoot int
State uint
KeyCode uint
SameScreen bool
State uint
KeyCode uint
SameScreen bool
}

func XNextEvent ( display *Display ) XEvent {
func XNextEvent(display *Display) XEvent {
displayC := (*C.Display)(display)
var xeventC C.XEvent
var xeventTypeC C.int
C.XNextEvent(displayC,&xeventC)
C.xlib_xevent_type(&xeventC,&xeventTypeC)
C.XNextEvent(displayC, &xeventC)
C.xlib_xevent_type(&xeventC, &xeventTypeC)

switch xeventTypeC {
case C.KeyPress:
return newXKeyEvent(&xeventC,xeventTypeC)
case C.KeyRelease:
return newXKeyEvent(&xeventC,xeventTypeC)
case C.KeyPress:
return newXKeyEvent(&xeventC, xeventTypeC)
case C.KeyRelease:
return newXKeyEvent(&xeventC, xeventTypeC)
}
return nil
}

func newXKeyEvent ( xeventC *C.XEvent, xeventTypeC C.int ) *XKeyEvent {
func newXKeyEvent(xeventC *C.XEvent, xeventTypeC C.int) *XKeyEvent {
xKeyEvent := new(XKeyEvent)
var serialC C.ulong; var sendEventC C.Bool; var displayC *C.Display; var windowC C.Window
var rootC C.Window; var subwindowC C.Window; var timeC C.Time; var xC, yC C.int
var xRootC, yRootC C.int; var stateC C.uint; var keyCodeC C.uint; var sameScreenC C.Bool
C.xlib_xkeyevent_values(xeventC,&serialC,&sendEventC,&displayC,&windowC,&rootC,&subwindowC,
&timeC,&xC,&yC,&xRootC,&yRootC,&stateC,&keyCodeC,&sameScreenC)
xKeyEvent.typeCode = int(xeventTypeC); xKeyEvent.Serial = uint64(serialC)
xKeyEvent.SendEvent = (sendEventC != 0); xKeyEvent.Display = (*Display)(displayC)
xKeyEvent.Window = Window(windowC); xKeyEvent.Root = Window(rootC)
xKeyEvent.Subwindow = Window(subwindowC); xKeyEvent.Time = uint64(timeC)
xKeyEvent.X = int(xC); xKeyEvent.Y = int(yC); xKeyEvent.XRoot = int(xRootC); xKeyEvent.YRoot = int(yRootC)
xKeyEvent.State = uint(stateC); xKeyEvent.KeyCode = uint(keyCodeC); xKeyEvent.SameScreen = (sameScreenC != 0)
var serialC C.ulong
var sendEventC C.Bool
var displayC *C.Display
var windowC C.Window
var rootC C.Window
var subwindowC C.Window
var timeC C.Time
var xC, yC C.int
var xRootC, yRootC C.int
var stateC C.uint
var keyCodeC C.uint
var sameScreenC C.Bool
C.xlib_xkeyevent_values(xeventC, &serialC, &sendEventC, &displayC, &windowC, &rootC, &subwindowC,
&timeC, &xC, &yC, &xRootC, &yRootC, &stateC, &keyCodeC, &sameScreenC)
xKeyEvent.typeCode = int(xeventTypeC)
xKeyEvent.Serial = uint64(serialC)
xKeyEvent.SendEvent = (sendEventC != 0)
xKeyEvent.Display = (*Display)(displayC)
xKeyEvent.Window = Window(windowC)
xKeyEvent.Root = Window(rootC)
xKeyEvent.Subwindow = Window(subwindowC)
xKeyEvent.Time = uint64(timeC)
xKeyEvent.X = int(xC)
xKeyEvent.Y = int(yC)
xKeyEvent.XRoot = int(xRootC)
xKeyEvent.YRoot = int(yRootC)
xKeyEvent.State = uint(stateC)
xKeyEvent.KeyCode = uint(keyCodeC)
xKeyEvent.SameScreen = (sameScreenC != 0)
return xKeyEvent
}

func (this *tEventType) Type ( ) int {
return this.typeCode
func XNextRequest(display *Display) uint64 {
displayC := (*C.Display)(display)
return uint64(C.XNextRequest(displayC))
}

func (ev *tEventType) Type() int {
return ev.typeCode
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/vbsw/xlib
module github.com/daviseidel/xlib

go 1.13
go 1.18
Loading