Skip to content

Commit

Permalink
fix: Fix Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
LightningDev1 committed Feb 12, 2024
1 parent c8504ce commit 852517d
Showing 1 changed file with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions foreground_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ func getActiveWindowID() (xproto.Window, error) {
defer conn.Close()

setup := xproto.Setup(conn)
screen := setup.DefaultScreen(conn)
root := screen.Root

activeWindow, err := xproto.GetProperty(
conn,
false,
root,
xproto.Atom("_NET_ACTIVE_WINDOW"),
xproto.Atom("WINDOW"),
0,
(1<<32)-1,
).Reply()
root := setup.DefaultScreen(conn).Root

aname := "_NET_ACTIVE_WINDOW"
activeAtom, err := xproto.InternAtom(conn, true, uint16(len(aname)), aname).Reply()
if err != nil {
return 0, err
}

return xproto.Window(activeWindow.Value[0]), nil
reply, err := xproto.GetProperty(conn, false, root, activeAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return 0, err
}

return xproto.Window(xgb.Get32(reply.Value)), nil
}

// GetForegroundPID returns the PID of the foreground window.
Expand All @@ -48,20 +46,19 @@ func GetForegroundPID() (uint32, error) {
}
defer conn.Close()

propReply, err := xproto.GetProperty(
conn,
false,
windowID,
xproto.Atom("_NET_WM_PID"),
xproto.Atom("CARDINAL"),
0,
(1<<32)-1,
).Reply()
aname := "_NET_WM_PID"
pidAtom, err := xproto.InternAtom(conn, true, uint16(len(aname)), aname).Reply()
if err != nil {
return 0, err
}

return propReply.Value32(), nil
reply, err := xproto.GetProperty(conn, false, windowID, pidAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return 0, err
}

return xgb.Get32(reply.Value), nil
}

// GetForegroundTitle returns the title of the foreground window.
Expand All @@ -77,18 +74,17 @@ func GetForegroundTitle() (string, error) {
}
defer conn.Close()

propReply, err := xproto.GetProperty(
conn,
false,
windowID,
xproto.Atom("_NET_WM_NAME"),
xproto.Atom("UTF8_STRING"),
0,
(1<<32)-1,
).Reply()
aname := "_NET_WM_NAME"
nameAtom, err := xproto.InternAtom(conn, true, uint16(len(aname)), aname).Reply()
if err != nil {
return "", err
}

reply, err := xproto.GetProperty(conn, false, windowID, nameAtom.Atom,
xproto.GetPropertyTypeAny, 0, (1<<32)-1).Reply()
if err != nil {
return "", err
}

return string(propReply.Value), nil
return string(reply.Value), nil
}

0 comments on commit 852517d

Please sign in to comment.