Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar-wayland
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar-wayland
Commits
6a60ce38
Commit
6a60ce38
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Connect to wayland socket
parent
7fe37b76
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
quasar-wayland.cabal
+3
-1
3 additions, 1 deletion
quasar-wayland.cabal
src/Quasar/Wayland/Client.hs
+70
-0
70 additions, 0 deletions
src/Quasar/Wayland/Client.hs
with
73 additions
and
1 deletion
quasar-wayland.cabal
+
3
−
1
View file @
6a60ce38
...
...
@@ -83,6 +83,7 @@ common shared-executable-properties
library
import: shared-properties
exposed-modules:
Quasar.Wayland.Client
Quasar.Wayland.Protocol
Quasar.Wayland.TH
build-depends:
...
...
@@ -90,8 +91,9 @@ library
--binary,
bytestring,
exceptions,
filepath,
--mtl,
--
network,
network,
quasar,
template-haskell,
--unix,
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Wayland/Client.hs
0 → 100644
+
70
−
0
View file @
6a60ce38
module
Quasar.Wayland.Client
(
connectWaylandClient
,
newWaylandClient
,
)
where
import
Control.Monad.Catch
import
Network.Socket
qualified
as
Socket
import
Network.Socket
(
Socket
)
import
Quasar.Disposable
import
Quasar.Prelude
import
Quasar.ResourceManager
import
System.Environment
(
getEnv
,
lookupEnv
)
import
System.FilePath
((
</>
),
isRelative
)
import
Text.Read
(
readEither
)
data
WaylandClient
=
WaylandClient
{
socket
::
Socket
,
resourceManager
::
ResourceManager
}
instance
IsResourceManager
WaylandClient
where
toResourceManager
client
=
client
.
resourceManager
instance
IsDisposable
WaylandClient
where
toDisposable
client
=
toDisposable
client
.
resourceManager
newWaylandClient
::
MonadResourceManager
m
=>
Socket
->
m
WaylandClient
newWaylandClient
socket
=
do
resourceManager
<-
newResourceManager
onResourceManager
resourceManager
do
registerDisposeAction
(
pure
()
<$
Socket
.
close
socket
)
pure
WaylandClient
{
socket
,
resourceManager
}
connectWaylandClient
::
MonadResourceManager
m
=>
m
WaylandClient
connectWaylandClient
=
mask_
do
socket
<-
liftIO
connectWaylandSocket
newWaylandClient
socket
where
connectWaylandSocket
::
IO
Socket
connectWaylandSocket
=
do
lookupEnv
"WAYLAND_SOCKET"
>>=
\
case
-- Parent process already established connection
Just
waylandSocketEnv
->
do
case
readEither
waylandSocketEnv
of
Left
err
->
fail
$
"Failed to parse WAYLAND_SOCKET: "
<>
err
Right
fd
->
Socket
.
mkSocket
fd
Nothing
->
do
path
<-
getWaylandSocketPath
newUnixSocket
path
getWaylandSocketPath
::
IO
FilePath
getWaylandSocketPath
=
do
waylandDisplayEnv
<-
lookupEnv
"WAYLAND_DISPLAY"
let
waylandDisplay
=
fromMaybe
"wayland-0"
waylandDisplayEnv
if
isRelative
waylandDisplay
then
do
xdgRuntimeDir
<-
getEnv
"XDG_RUNTIME_DIR"
pure
(
xdgRuntimeDir
</>
waylandDisplay
)
else
pure
waylandDisplay
newUnixSocket
::
FilePath
->
IO
Socket
newUnixSocket
socketPath
=
bracketOnError
(
Socket
.
socket
Socket
.
AF_UNIX
Socket
.
Stream
Socket
.
defaultProtocol
)
Socket
.
close
$
\
sock
->
do
Socket
.
withFdSocket
sock
Socket
.
setCloseOnExecIfNeeded
Socket
.
connect
sock
$
Socket
.
SockAddrUnix
socketPath
pure
sock
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment