Commit Graph

1074 Commits

Author SHA1 Message Date
Geoffrey McRae
5aa7a391ac [client] x11: implement center, borderless and maximized parameters 2021-03-27 11:17:48 +11:00
Geoffrey McRae
1bf9fb7d73 [client] x11: fix segfault caused by clipboard processing on shutdown 2021-03-27 10:06:57 +11:00
Geoffrey McRae
84d4c18c48 [client] x11: split out atoms into a seperate structure 2021-03-27 10:05:57 +11:00
Geoffrey McRae
2f14d64289 [client] x11: split out clipboard code for maintainabillity 2021-03-27 09:21:32 +11:00
Geoffrey McRae
ab4d7cb94b [client] x11: _NET_WM_* hints are ATOMS not CARDINAL
This fixes the fullscreen and likely borderless issue too that people
have been reporting on X11 under gnome. Thanks to tdb in discord for
spotting the error.
2021-03-25 09:29:06 +11:00
Quantum
ba3243f88a [client] wayland: make input handlers aware of multiple surfaces
This prevents input handlers from breaking in presence of subsurfaces,
which are used by libdecor for client-side decorations.
2021-03-15 10:54:35 +11:00
Quantum
d6a290a31d [client] wayland: implement libdecor pseudo-shell backend
This allows decorations to be drawn on GNOME and other crazy compositors
that do not support server-side decorations.
2021-03-15 10:54:35 +11:00
Quantum
82e107af8a [client] cmake: support building with libdecor 2021-03-15 10:54:35 +11:00
Quantum
4031a862df [client] wayland: split xdg-shell handling into a module
This will allow libdecor to be added as a new pseudo-shell.
2021-03-15 10:54:35 +11:00
Quantum
854b53e28c [client] wayland: use consistent naming in poll module
Some of the functions were named WaylandEpoll*, which is inconsistent.
This commit changed them to be WaylandPoll*.
2021-03-03 16:38:23 +11:00
Quantum
fc7dd7dbb7 [common] cmake: correctly link static libbfd.a
When linking against libbfd.so, just passing libbfd.so to the compiler is
sufficient. When linking against the static version libbfd.a, however,
we must additionally link against libiberty.a and libz.a.

This commit adds a CMake helper to find the correct libraries that need
to be passed to link against libbfd correctly.
2021-03-03 16:37:34 +11:00
Tudor Brindus
484012a90c [client] wayland: bind no-op drag-and-drop handlers
Otherwise, libwayland aborts when a drag into the Looking Glass window
occurs.
2021-02-27 14:49:06 +11:00
Tudor Brindus
97009027d1 [client] wayland: require wl_compositor v3 instead of v4
The only addition to v4 was `wl_surface_damage_buffer`, which we do not
use.

This change should allow running on more compositors (even though v4 is
already old -- 5 years now).

Ref
3384f69ecf.
2021-02-27 14:48:40 +11:00
Tudor Brindus
d6b8823dce [client] wayland: gracefully downgrade to wl_output v2
We don't necessarily need `wl_output.release`, which is the only
addition in v3.

This allows Looking Glass to run on Ubuntu 20.04 without having to go
difficult lengths to acquire newer Wayland packages. Since 20.04 is an
LTS release, this seems worthwhile for the small amount of complexity
this introduces.

Fixes
https://forum.level1techs.com/t/latest-build-allow-inhibiting-shortcuts-dialog-ubuntu/168684/6.
2021-02-27 14:48:28 +11:00
Quantum
31c1452451 [client] readme: remove mention of Wayland's lack of warp
We have an implementation of Wayland cursor warping now, so there is no
need for the section saying that Wayland lacks the feature.
2021-02-26 10:29:07 +11:00
Quantum
8c6cff012d [client] readme: remove mention of SDL
SDL is default to off and its usage should not be encouraged, so
-DENABLE_SDL=ON is not mentioned as an option in the README.
2021-02-26 10:28:51 +11:00
Quantum
c34fe10f23 [client] ds: make SDL display server optional
This commit also moved the SDL dependencies into the SDL backend so that
-DENABLE_SDL=NO builds do not link against SDL.
2021-02-26 10:28:51 +11:00
Geoffrey McRae
f3b46e6d4f [client] app: delay showing the escape help for 250ms
This change prevents the help text being shown unless the escape key has
been held for a minimum of 250ms (reduced from 500ms).
2021-02-26 10:21:56 +11:00
Quantum
521ac706c1 [client] app: do not toggle capture if escapeKey is held
When users press escapeKey for a long time, they probably want to
see the help text instead of actually toggling capture. Therefore,
if the key is held down for more than 500 ms, we assume the user
wants to look at the help text and do not toggle capture mode.

500 ms seems to be a decent compromise, allowing slow presses, but
is not enough time for the user to have looked at the help text.
2021-02-26 09:59:17 +11:00
Quantum
9886c2bf40 [client] fonts: remove SDL font backend 2021-02-26 09:58:21 +11:00
Geoffrey McRae
c96ee0f786 [client] font: fix left shift runtime error due to signed shift 2021-02-26 09:54:08 +11:00
Quantum
5551420983 [client] wayland: clean up #includes in wayland.c
This was missed when splitting up wayland.c into multiple modules.
This commit also drops the useless #include <SDL2/SDL.h>, bringing
SDL removal one step closer.
2021-02-26 09:44:59 +11:00
Quantum
84e14edfe7 [client] opengl: remove dependency on SDL 2021-02-26 09:44:34 +11:00
Quantum
798a1aadb5 [client] wayland: fail gracefully when interfaces are too old
Before, we just attempt to bind, causing an obscure Wayland error.
This commit checks the interface versions and print better error
messages.
2021-02-26 09:43:38 +11:00
Quantum
1111045546 [client] freetype: implement UTF-8 handling 2021-02-26 09:43:06 +11:00
Quantum
5a075744bd [client] fonts: add freetype font rendering backend 2021-02-26 09:43:06 +11:00
Quantum
2da81e0b5a [client] display correct log path on Windows
We moved it to %ProgramData%\Looking Glass (host), but the client still
says it's in %TEMP%.
2021-02-23 20:28:48 +11:00
Quantum
389d8824e2 [client] wayland: handle output scale changes
If the scale factor of an wl_output changes while the client is running,
the maximum scale factor is not updated. This may result in incorrect
scaling.

Therefore, when the scale factor is changed, we should generate a
resize event.
2021-02-23 20:28:25 +11:00
Geoffrey McRae
8771103abb [client] all: fix more maybe-uninitialized when -O3 is in use
Closes #475
2021-02-23 20:25:30 +11:00
Geoffrey McRae
9e2cfb9106 [client] core: fix reversed logic and document the rationale for it
During the refactor/rebase period with B3-next the conditional was
accidentally reversed. This would cause the cursor to be ungrabbed
simply when toggling capture mode instead of waiting for the cursor to
exit the window.
2021-02-23 20:19:35 +11:00
Geoffrey McRae
a8ab559de0 [client] core: increase autoCapture false exit detection sensitivity
Mouse move deltas greater then 10 are rare, let alone the 20 this code
now uses. Any movements that exceed 20 pixels will disable the exit
detection code path preventing rapid movements in FPV games from causing
the cursor to exit the window if autoCapture is enabled.
2021-02-23 20:06:44 +11:00
Geoffrey McRae
78f4249496 [client] core: remove unnecessary warp and update of cursor location
As we now are using our own backends instead of SDL, there is no longer
any need to warp back to the center of the window when in autoCapture
mode. This breaks the SDL ds backend behaviour, however as SDL is
planned to be removed this is not an issue.
2021-02-23 20:06:44 +11:00
Geoffrey McRae
9ae53aca70 [client] doc: update license output copyright date 2021-02-23 20:06:44 +11:00
Quantum
30b5287c38 [client] egl: add option to set initial scale algorithm
The option is egl:scale. The scale algorithm number is displayed on the
alert to make it easier to specify the number for the option.
2021-02-22 17:25:06 +11:00
Quantum
0512c88ea8 [client] egl: make scale algorithms toggleable
The $escape+S keybinding now cycles through the available scale algorithms.
This allows the user to switch between algorithms if the automatic detection
turns out to be problematic.

The algorithms are renumbered so that 0 can be LG_SCALE_AUTO.
2021-02-22 17:25:06 +11:00
Quantum
46758efc8f [client] cmake: build for nehalem when OPTIMIZE_FOR_NATIVE=NO
We need SSE intrinsics like _mm_stream_load_si128 which is only available
on CPUs of nehalem or newer.
2021-02-22 11:25:44 +11:00
Geoffrey McRae
e79661a924 [client] app: fix format-truncation false positive
This is fixed by using the `valloc_sprintf` function provided in
common/stringutils.h as the functionallity is literally identical.
2021-02-22 01:39:56 +11:00
Geoffrey McRae
28024de314 [client] egl: fix gcc false maybe-uninitialized positives 2021-02-22 01:38:26 +11:00
Quantum
63ec2dc01b [client] egl: destroy cached EGLImages when changing format
Reusing cached EGLImages while the frame format has changed will result
in visual artifacts. We should instead destroy the EGLImages and let
them be recreated.
2021-02-21 19:07:46 +11:00
Quantum
48be58378c [client] opengl: scale UI elements on high DPI displays
This is done by simply scaling up the rendered text bitmap.
2021-02-21 19:06:53 +11:00
Quantum
fd50426dda [client] egl: scale UI elements on high DPI displays
This is done by actually rendering the text at high DPI.
2021-02-21 19:06:53 +11:00
Quantum
89bdaec95a [client] opengl: support scaled UI for high DPI displays 2021-02-21 19:06:53 +11:00
Quantum
3ec73e2444 [client] egl: support scaled UI for high DPI displays 2021-02-21 19:06:53 +11:00
Quantum
447aedc9a3 [client] wayland: pass scale factor information to renderer 2021-02-21 19:06:53 +11:00
Quantum
b35e19fc27 [client] renderer: add interface for high DPI rendering 2021-02-21 19:06:53 +11:00
Quantum
6b26089353 [client] wayland: keep track of wl_output scale information
This will later be used to control the size of the underlying EGL buffers
in order to handle high DPI.
2021-02-21 19:06:53 +11:00
Quantum
e46cadb211 [client] egl: generate header file with #define for desktop shader
Instead of duplicating the #defines from the shader into the C code,
this commit adds a custom CMake rule that exports all the #defines
from a shader into a C header.
2021-02-21 14:20:41 +11:00
Quantum
ba6f26393f [client] egl: add framework for multiple scaling algorithms
This commit fixes the issues with the meaning of useNearest being flipped
by removing the variable and use enumerations.

We define an enumeration EGL_DesktopScaleType to express the type of scaling
needed to be performed: no scaling, upscaling, or downscaling. This is
updated when either the frame size or the viewport size changes.
Previously, we only updated the useNearest when the frame size changes.

The desktop shader can now support an enumeration of scaling algorithms,
although only nearest and linear are currently implemented.

Like before, nearest is used when not scaling or upscaling, and linear is
used when downscaling.
2021-02-21 14:20:41 +11:00
Quantum
39a09ca565 [client] egl: remove dependency on SDL
After this PR, EGL functions are now accessed through <EGL/egl.h>
instead of through <SDL2/SDL_egl.h>, removing a pointless dependency
on SDL.
2021-02-21 10:31:49 +11:00
Quantum
5649d1ad95 [client] wayland: split Wayland display server into modules
The Wayland display server is getting unwieldy due to the sheer size.
To make it easier to edit in the future, I split it into many components
based on logical boundaries.
2021-02-21 10:31:49 +11:00
Quantum
1ba1108099 [client] wayland: add option to enable cursor warp
This is enabled on default. Specify wayland:warpSupport=no to disable it,
which may be useful on certain compositors that do not warp when the
pointer is confined.
2021-02-21 10:31:49 +11:00
Quantum
9b688909b0 [client] wayland: support LG_DS_WARP_SURFACE
This commit implements support for LG_DS_WARP_SURFACE, as well as a warp
routine based on cursor confines.

This may not necessarily work for all compositors. As such, the old cursor
routines are still kept, and used when wm.warpSupport is set to false.
2021-02-21 10:31:49 +11:00
Quantum
270631f1b9 [client] ds: add surface-only warp variant
This commit converts the output of ds->getProp(LG_DS_WARP_SUPPORT) to
an enum containing three items:

* LG_DS_WARP_NONE: warp is not supported at all
* LG_DS_WARP_SURFACE: warp is possible, but only inside the window
* LG_DS_WARP_SCREEN: warp is possible anywhere on the screen

LG_DS_WARP_NONE corresponds to the old false return value, and
LG_DS_WARP_SCREEN corresponds to the old true return value.

LG_DS_WARP_SURFACE is designed for Wayland, where warping is possible,
but only in our window. In this case, since we cannot warp outside
the window, we can warp the cursor to the edge when we attempt to exit.
If the cursor leaves, the normal leave routine gets called, and the
cursor disappears. If the cursor does not end up leaving, we grab it
again.
2021-02-21 10:31:49 +11:00
Tudor Brindus
1a407a67b1 [client] input: add releaseKeysOnFocusLoss option
This makes dealing with window manager shortcuts that overlap with guest
keys more pleasant, while retaining the previous functionality for users
who prefer it.

For instance, previously, using Alt+Tab (or $mod as Alt in i3/sway
movement commands) would result in the guest retaining Alt as pressed.

When the guest regained focus, it would continue thinking Alt is
pressed, leading to accidentally triggering obscure shortcuts. One had
to remember to press Alt again to "unstick" things, which was
suboptimal.
2021-02-21 10:31:49 +11:00
Quantum
98a327e99e [client] wayland: make clipboard writes asynchronous
This allows multiple Wayland clients to stream data from looking glass
without blocking the looking glass main thread.
2021-02-21 10:31:49 +11:00
Quantum
800f063a1d [client] wayland: make clipboard read async
This allows reading from the clipboard without blocking the UI thread.
2021-02-21 10:31:49 +11:00
Quantum
e01666b6ad [client] wayland: implement epoll registration mechanism
This will be used to register async clipboard I/O callbacks later.
2021-02-21 10:31:49 +11:00
Quantum
30a888711b [client] egl: force DMA copy into texture in on_frame
This commit forces the DMA'd memory to be copied into the texture in
the EGL on_frame handler. This avoids tearing when the LG host inevitably
updates the underlying memory. We need an additional copy inside the GPU,
but this is cheap compared to copying from system memory.

We could have used logic to lock the memory buffer, but that would require
performing DMA on every frame, which wastes memory bandwidth. This
manifests as reduced frame rate when moving the mouse compared to the
non-DMA implementation.

We also keep multiple EGLImages, one for each DMA fd, to avoid issues
with the OpenGL driver.
2021-02-21 10:31:48 +11:00
Quantum
a450e0f8f5 [client] wayland: better self-copy detection
This new implementation uses a special mimetype to tag data copied from
the guest, instead of using flags. This should make it easier to
implement asynchronous transfers in the future. Also, it's simpler to
understand and less error-prone.

The pid is included in the mimetype in order to distinguish between
different instances of looking glass: you might want to copy between
two different VMs, for example.
2021-02-21 10:31:48 +11:00
Quantum
0c9ecdfcb5 [client] wm: optionally disable screensaver when requested in guest
This commit adds a new option, win:autoScreensaver, which when set to yes,
automatically disables the screensaver when requested by an application
running in the guest, and enables it when the application no longer wants
it disabled.

This is useful when doing media playback in the guest.
2021-02-21 10:31:48 +11:00
Quantum
cc2104c699 [client] wayland: cleanup surface and display
These used to be owned by SDL and can't be cleaned up. This has since
changed.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
c6af5be1dc [client] app: always track the mouse button state
This change fixes a bug on re-grab of the cursor if window focus was
lost while a mouse button was held.
2021-02-21 10:31:48 +11:00
Quantum
06f6a96b56 [client] spice: fix input:grabKeyboardOnFocus
It appears that the keyboard should only be grabbed if the client is
focused and the cursor is in the view. However, the relevant logic was
missing from core_setCursorInView, and the keyboard was never actually
grabbed.

This commit adds the call to g_state.ds->grabKeyboard(), allowing grabbing
to work.
2021-02-21 10:31:48 +11:00
Quantum
89b73512ad [client] renderer: add ability to toggle the FPS display
Before, if you want to see the FPS, you need to close the client and
restart it with the -k switch to see the FPS. This is annoying.

This PR introduces a new keybind, ScrollLock+D, which, when pressed,
toggles the display of the FPS.

This is implemented for both EGL and OpenGL backends.
2021-02-21 10:31:48 +11:00
Quantum
b45f7a6733 [client] egl: fix race condition in help overlay
egl_help_set_text and egl_help_render were both accessing bmp->help from
different threads. This creates a race condition in which if the help text
is quickly toggled on and off, it stays on.

This has been fixed with an atomic exchange.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
1d99c821eb [client] egl: decrease the font size for the help text 2021-02-21 10:31:48 +11:00
Quantum
2993f7ae7d [client] egl: create 24-bit colour context
This should prevent the looking-glass-client window from having an alpha
channel. On Wayland, the alpha channel is used to compose the window onto
the desktop, so the wallpaper would bleed through unless set to complete
opaque.

We worked around this by using constant alpha for rendering, but it was
not sustainable. Instead, we should just ask for 24-bit context.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
5454053d96 [client] x11: set the window class name 2021-02-21 10:31:48 +11:00
Geoffrey McRae
17d423db06 [client] x11: handle window deletion properly 2021-02-21 10:31:48 +11:00
Quantum
5ac53362a3 [client] renderer/egl: implement support for rendering help text
The help text is rendered in the bottom left corner on a semi-transparent
background, very similar to how the FPS text is rendered.
2021-02-21 10:31:48 +11:00
Quantum
17b0e2cb22 [client] fonts: support rendering multiline text with SDL 2021-02-21 10:31:48 +11:00
Quantum
96dc8c602c [client] keybind: display help overlay while ScrollLock is held
This overlay will show the list of keybindings.
2021-02-21 10:31:48 +11:00
Quantum
ead8069dae [client] keybind: add descriptions for all keybindings 2021-02-21 10:31:48 +11:00
Quantum
4e765b063a [client] kb: add display names for all supported keys 2021-02-21 10:31:48 +11:00
Quantum
5dce97264b [client] renderers: add on_help to renderer interface
This will be used to tell a render to display a help message.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
a00a6429d3 [client] app: fix spelling error 2021-02-21 10:31:48 +11:00
Geoffrey McRae
aafdec02df [client] wayland: fix mouse code post refactor 2021-02-21 10:31:48 +11:00
Geoffrey McRae
4e1c0cc0d0 [client] ds: refactor app and cursor state into app.c and core.c 2021-02-21 10:31:48 +11:00
Geoffrey McRae
33fed48277 [client] app: fix broken mouse sensitivity 2021-02-21 10:31:48 +11:00
Quantum
b0f9d2f713 [client] spice/wayland: improve cursor tracking logic
One of the major issues with the old tracking code is a data race
between the cursor thread updating g_cursor.guest and the
app_handleMouseBasic function. Specifically, the latter may have
sent mouse input via spice that has not been processed by the guest
and updated g_cursor.guest, but the guest may overwrite g_cursor.guest
to a previous state before the input is processed. This causes some
movements to be doubled. Eventually, the cursor positions will
synchronize, but this nevertheless causes a lot of jitter.

In this commit, we introduce a new field g_cursor.projected, which
is unambiguously the position of the cursor after taking into account
all the input already sent via spice. This is synced up to the guest
cursor upon entering the window and when the host restarts. Afterwards,
all mouse movements will be based on this position. This eliminates
all cursor jitter as far as I could tell.

Also, the cursor is now synced to the host position when exiting
capture mode.

A downside of this commit is that if the 1:1 movement patch is not
correctly applied, the cursor position would be wildly off instead
of simply jittering, but that is an unsupported configuration and
should not matter.

Also unsupported is when an application in guest moves the cursor
programmatically and bypassing spice. When using those applications,
capture mode must be on. Before this commit, we try to move the guest
cursor back to where it should be, but it's inherently fragile and
may lead to scenarios such as wild movements in first-person shooters.
2021-02-21 10:31:48 +11:00
Quantum
543d660ccc [client] wayland: check for the Wayland platform extension
We used to test for the EGL_KHR_platform_base and EGL_EXT_platform_base,
but those only really signal the availability of eglGetPlatformDisplay(EXT)
functions, not whether the constant EGL_PLATFORM_WAYLAND_KHR or
EGL_PLATFORM_WAYLAND_EXT is accepted by their respective functions.

Instead, we switch to test for the extensions that tells us whether the
Wayland platform is supported.
2021-02-21 10:31:48 +11:00
Quantum
ecebcc4c35 [client] opengl: make ds functions optional
Using a macro ENABLE_OPENGL just like ENABLE_EGL to optionally remove
OpenGL implementation code. This is mostly because on Wayland it's just
a rehash of the EGL code (as EGL is the only way to create OpenGL
contexts on Wayland).
2021-02-21 10:31:48 +11:00
Quantum
af2dafbdac [client] wayland: add ability to create OpenGL contexts
This should allow the OpenGL backend to work.
2021-02-21 10:31:48 +11:00
Quantum
a56e363e39 [client] wayland: add stubs for OpenGL functions
This allows the client to run on Wayland, even though OpenGL doesn't work.
2021-02-21 10:31:48 +11:00
Geoffrey McRae
06af101bf9 [client] x11: properly handle window destruction and fullscreen support 2021-02-21 10:31:48 +11:00
Geoffrey McRae
973806dd9c [client] opengl: implement & fix opengl support 2021-02-21 10:31:48 +11:00
Geoffrey McRae
740dad943b [client] x11: cleanup on failure to initialize 2021-02-21 10:31:48 +11:00
Geoffrey McRae
4dfe4b8e2b [client] allow renderers to pass back if they need an OpenGL context 2021-02-21 10:31:48 +11:00
Geoffrey McRae
cc521eab90 [client] app: fix reversed ds init logic 2021-02-21 10:31:48 +11:00
Geoffrey McRae
7d2c9ec447 [client] app: don't call ds->free if the ds was not initialized 2021-02-21 10:31:48 +11:00
Geoffrey McRae
8919d2718f [client] egl: fix building without EGL support 2021-02-21 10:31:48 +11:00
Tudor Brindus
cf3e816603 [client] probe Wayland backend first
`$DISPLAY` will be set even in a Wayland session, which causes LG to
initialize itself under Xwayland unless it is explicitly compiled with
`-DENABLE_X11=OFF`.

We could add a Wayland check within the X11 backend, but reordering the
code-generated array seems like a better solution.
2021-02-21 10:31:48 +11:00
Quantum
b8bf980a29 [client] wayland: decorate window unless borderless is requested
Show server-side decoration with the xdg_decoration protocol unless
win:borderless=yes.
2021-02-21 10:31:48 +11:00
Quantum
5dad69675b [client] wayland: respect request to maximize window
Request the compositor to maximize the window if win:maximize=yes.
2021-02-21 10:31:48 +11:00
Quantum
d0d1b31c10 [client] wayland: add handling for close event
When the xdg_toplevel receives a close event, call app_handleCloseEvent.
2021-02-21 10:31:48 +11:00
Quantum
6206d5dec4 [client] wayland: implement full screen handling
Implement waylandSetFullscreen and waylandGetFullscreen.
2021-02-21 10:31:48 +11:00
Quantum
265370b0f5 [client] wayland: implement cursor handling
This commit adds code to load the looking glass cursor and display it
when needed. Otherwise, the cursor is hidden.
2021-02-21 10:31:48 +11:00
Quantum
081d76268a [client] wayland: handle mouse/keyboard enter events
This allows mouse and keyboard input to work again on Wayland.
2021-02-21 10:31:48 +11:00
Quantum
8559b354ae [client] egl: always render desktop texture as opaque
We ask for 32-bit colour buffer when creating the EGL context. On Wayland,
this sometimes give contexts with alpha channels, resulting in unwanted
transparency. So we clear the alpha channel in the desktop shader.

We also switch to using constant alpha for blending the splash, which
avoids more alpha issues.
2021-02-21 10:31:48 +11:00
Quantum
9f0b99dac0 [client] wayland: implement window creation for egl
This commit implements window creation and resize logic, allowing the desktop
to be drawn.
2021-02-21 10:31:48 +11:00