Commit Graph

2250 Commits

Author SHA1 Message Date
Alex Richardson d83c84bd9d Mark the dixChangeWindowProperty() value argument as const
It is copied using memcpy() and not modified so we can add const. This
fixes a -Wincompatible-pointer-types-discards-qualifiers compiler warning
that was failing a -Werror XVnc build for me.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-07-30 08:36:35 +00:00
Olivier Fourdan 6b47321bc6 dix: Add optional terminate delay
When the command line option "-terminate" is used, it could be
interesting to give it an optional grace period to let the Xserver
running for a little longer in case a new connection occurs.

This adds an optional parameter to the "-terminate" command line option
for this purpose.

v2: Use a delay in seconds instead of milliseconds
    (Martin Peres <martin.peres@mupuf.org>)
v3: Clarify man page entry, ensure terminateDelay is always >= 0,
    simplify TimerFree(). (Peter Hutterer <peter.hutterer@who-t.net>)

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-07 17:28:05 +02:00
Olivier Fourdan e167299f60 xfixes: Add ClientDisconnectMode
With Wayland compositors now being able to start Xwayland on demand, the
next logical step is to be able to stop Xwayland when there is no more
need for it.

The Xserver itself is capable of terminating itself once all X11 clients
are gone, yet in a typical full session, there are a number of X11
clients running continuously (e.g. the Xsettings daemon, IBus, etc.).

Those always-running clients will prevent the Xserver from terminating,
because the actual number of X11 clients will never drop to 0. Worse,
the X11 window manager of a Wayland compositor also counts as an X11
client, hence also preventing Xwayland from stopping.

Some compositors such as mutter use the XRes extension to query the X11
clients connected, match their PID with the actual executable name and
compare those with a list of executables that can be ignored when
deciding to kill the Xserver.

But that's not just clumsy, it is also racy, because a new X11 client
might initiate a connection the X11 server right when the compositor is
about to kill it.

To solve this issue directly at the Xserver level, this add new entries
to the XFixes extension to let the X11 clients themselves specify the
disconnect mode they expect.

Typically, those X11 daemon clients would specify the disconnect mode
XFixesClientDisconnectFlagTerminate to let the Xserver know that they
should not be accounted for when checking the remaining clients prior
to terminate.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-07 17:28:05 +02:00
Povilas Kanapickas 5163fc8bc2 Implement gesture processing logic 2021-05-30 13:26:42 +03:00
Povilas Kanapickas 100a2ad6da dix: Implement gesture event submission code path 2021-05-30 13:26:40 +03:00
Povilas Kanapickas 7656a9c8dd dix: Implement internal gesture state handling 2021-05-30 13:26:39 +03:00
Povilas Kanapickas 0bf4123fd3 dix: Implement gesture event fixups before delivery 2021-05-30 13:26:38 +03:00
Povilas Kanapickas 227f601de3 xi: Implement conversions from internal to Xi2 gesture event structs 2021-05-30 13:26:37 +03:00
Povilas Kanapickas 080bac39c8 xi: Implement grab support for new gesture event types 2021-05-30 13:26:32 +03:00
Povilas Kanapickas 22fa31ed56 dix: Add new internal event enums for gesture events 2021-05-30 13:26:30 +03:00
Povilas Kanapickas 99e7ccffb3 dix: Fix URL to description of focus in/out model
The current URL points to an unrelated patch for acpid.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-03-25 23:18:14 +02:00
Povilas Kanapickas af17b5c499 dix: Use correct listener to deliver touch end events
This fixes an problem left in f682e0563f
due to an incorrect cherry-pick.

We must use old listener->listener to deliver the touch event. Otherwise
grab won't let the event through and the abovementioned commit has no
effect.

Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-02-17 04:29:48 +00:00
Olivier Fourdan dee2bb033e dix: Guard against non-existing PtrFeedbackPtr
Trying to change the pointer control settings on a device without
PtrFeedbackPtr would be a bug and a crash in the Xserver.

Guard against that case by returning early with a BadImplementation
error, that might kill the X11 client but the Xserver would survive.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Related: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1137
2021-02-16 09:37:46 +01:00
Olivier Fourdan b5e1f13681 dix: Add POINTER_RAWONLY flag
This add a new flag POINTER_RAWONLY for GetPointerEvents() which does
pretty much the opposite of POINTER_NORAW.

Basically, this tells GetPointerEvents() that we only want the
DeviceChanged events and any raw events for this motion but no actual
motion events.

This is preliminary work for Xwayland to be able to use relative motion
events for raw events. Xwayland would use absolute events for raw
events, but some X11 clients (wrongly) assume raw events to be always
relative.

To allow such clients to work with Xwayland, it needs to switch to
relative raw events (if those are available from the Wayland
compositor).

However, Xwayland cannot use relative motion events for actual pointer
location because that would cause a drift over time, the pointer being
actually controlled by the Wayland compositor.

So Xwayland needs to be able to send only relative raw events, hence
this API.

Bump the ABI_XINPUT_VERSION minor version to reflect that API addition.

v2: Actually avoid sending motion events (Peter)
v3: Keep sending raw emulated events with RAWONLY (Peter)

Suggested-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Related: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1130
2021-02-15 09:42:00 +01:00
Povilas Kanapickas f682e0563f dix: Send touch end to clients that do async grab without touch events
If a XI2 client started listening to touches due to a selection and then
creates an active async grab that does not include touch events, then it
currently won't get the touch end event which will produce inconsistent
view of the pending touches.

Note that we only need to consider touch listeners and can ignore
pointer emulation. Under XI2 if a active grab replaces a passive
implicit grab and the active grab does not include the button release
event, the client won't get it either.
2021-02-08 05:21:29 +02:00
Povilas Kanapickas f5220117e9 dix: Extract FreezeThisEventIfNeededForSyncGrab() 2020-11-25 04:20:22 +00:00
Povilas Kanapickas 36f8dacc06 dix: Extract ActivateGrabNoDeliver() 2020-11-25 04:20:22 +00:00
Povilas Kanapickas 23a8b62d34 dix: Store replayed event into GrabInfoRec struct as InternalEvent* 2020-11-25 04:20:22 +00:00
Povilas Kanapickas 8bd8b3af19 dix: Rename LISTENER_* to TOUCH_LISTENER_* 2020-11-25 04:20:22 +00:00
Povilas Kanapickas 56d7205921 dix: Extract DeliverDeviceClassesChangedEvent() utility function 2020-11-25 04:20:21 +00:00
Povilas Kanapickas 5b0c5344b7 dix: Extract CopySprite() utility 2020-11-25 04:20:21 +00:00
Povilas Kanapickas acd819ac07 dix: Extract FixUpXI2DeviceEventFromWindow() 2020-11-25 04:20:21 +00:00
Alan Coopersmith d00594ebc7 AddInputDevice: only need to check once if we failed to calloc dev
Resolves warning from Oracle Parfait static analyser:

Warning: Impossible or redundant condition
   Impossible or redundant condition [impossible-redundant-condition]:
      Condition 'dev != NULL' of branch is determined by previous branch
        at line 270 of dix/devices.c in function 'AddInputDevice'.
          Condition 'dev != NULL' from this branch implies following branch is always true at line 262

Fixes: commit 493ad83323
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-11-17 18:43:39 -08:00
Matthieu Herrb aac28e162e fix for ZDI-11426
Avoid leaking un-initalized memory to clients by zeroing the
whole pixmap on initial allocation.

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-31 14:51:23 +00:00
Dave Airlie ea47af87f6 xserver/output: rename some badly named variables/APIs.
This is an API and ABI break

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-10 06:17:44 +10:00
Alan Coopersmith 23e83724df Fix spelling/wording issues
Most (but not all) of these were found by using
  codespell --builtin clear,rare,usage,informal,code,names
but not everything reported by that was fixed.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-05 13:07:33 -07:00
Aaron Plattner 4308f5d3d1 os: Don't crash in AttendClient if the client is gone
If a client is in the process of being closed down, then its client->osPrivate
pointer will be set to NULL by CloseDownConnection. This can cause a crash if
freeing the client's resources results in a call to AttendClient. For example,
if the client has a pending sync fence:

 Thread 1 "X" received signal SIGSEGV, Segmentation fault.
 AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942
 (gdb) bt
 #0  AttendClient (client=0x5571c4aed9a0) at ../os/connection.c:942
 #1  0x00005571c3dbb865 in SyncAwaitTriggerFired (pTrigger=<optimized out>) at ../Xext/sync.c:694
 #2  0x00005571c3dd5749 in miSyncDestroyFence (pFence=0x5571c5063980) at ../miext/sync/misync.c:120
 #3  0x00005571c3dbbc69 in FreeFence (obj=<optimized out>, id=<optimized out>) at ../Xext/sync.c:1909
 #4  0x00005571c3d7a01d in doFreeResource (res=0x5571c506e3d0, skip=skip@entry=0) at ../dix/resource.c:880
 #5  0x00005571c3d7b1dc in FreeClientResources (client=0x5571c4aed9a0) at ../dix/resource.c:1146
 #6  FreeClientResources (client=0x5571c4aed9a0) at ../dix/resource.c:1109
 #7  0x00005571c3d5525f in CloseDownClient (client=0x5571c4aed9a0) at ../dix/dispatch.c:3473
 #8  0x00005571c3d55eeb in Dispatch () at ../dix/dispatch.c:492
 #9  0x00005571c3d59e96 in dix_main (argc=3, argv=0x7ffe7854bc28, envp=<optimized out>) at ../dix/main.c:276
 #10 0x00007fea4837cb6b in __libc_start_main (main=0x5571c3d1d060 <main>, argc=3, argv=0x7ffe7854bc28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe7854bc18) at ../csu/libc-start.c:308
 #11 0x00005571c3d1d09a in _start () at ../Xext/sync.c:2378
 (gdb) print client->osPrivate
 $1 = (void *) 0x0

Since the client is about to be freed, its ignore count doesn't matter and
AttendClient can simply be a no-op. Check for client->clientGone in AttendClient
and remove similar checks from two callers that had them.

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
2019-11-19 10:15:05 -08:00
Adam Jackson 516e75dbb6 dix: Call SourceValidate before GetImage
This ensures that any prep work for the drawable we're about to read
from is already done before we call down to GetImage. This should be no
functional change as most of the callers with a non-trivial
SourceValidate are already wrapping GetImage and doing the equivalent
thing, but we'll be simplifying that shortly.

More importantly this ensures that if any of that prep work would
generate events - like automatic compositing flushing rendering to a
parent pixmap which then triggers damage - then it happens entirely
before we start writing the GetImage reply header.

Note that we do not do the same for GetSpans, but that's okay. The only
way to get to GetSpans is through miCopyArea or miCopyPlane - where the
callers must already call SourceValidate - or miGetImage - which this
commit now protects with SourceValidate.

Fixes: xorg/xserver#902
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-10-30 16:26:01 +00:00
Adam Jackson ff310903f3 mi: Add a default no-op miSourceValidate
Slightly simplifies the callers since they don't need to check for
non-NULL anymore.

I do extremely hate the workarounds here to suppress misprite taking the
cursor down though. Surely there's a better way.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-10-30 16:26:01 +00:00
Adam Jackson 89a9927b1e include: Remove now-empty site.h 2019-10-30 16:17:04 +00:00
Adam Jackson ff4e2c24ec dix: Move default screensaver defaults into globals.c 2019-10-30 16:17:04 +00:00
Adam Jackson 2d1ed64d2a dix: Remove -to option to set the default connection timeout
One minute is admittedly arbitrary, but again, pretty sure this never
gets set on the command line in practice.
2019-10-30 16:17:04 +00:00
Adam Jackson 56ea4c769c dix: Remove -fn and -fc options to set default text/cursor fonts
I strongly suspect these never get used in the wild, and it's not an
especially useful thing to do in any case.
2019-10-30 16:17:04 +00:00
Adam Jackson ec659f021e dix: Remove now-unused SetVendorString 2019-10-30 16:17:04 +00:00
Adam Jackson 592525386a dix: Fix undefined memset in _dixInitScreenPrivates
Again, memset(0, ...) is undefined.
2019-10-15 14:06:50 -04:00
Adam Jackson 1e5f478b7e dix: Fix undefined shift in HashResourceID
Again, we need all of the bits of an unsigned int to make this work.
2019-10-15 14:06:21 -04:00
Adam Jackson a41d45eedc dix: Fix undefined memset in dixInitPrivates
When we set these up initially, no subsystems have allocated any
privates yet, so the storage address will be null, and memset(NULL, ...)
is undefined.
2019-10-15 14:05:38 -04:00
Hans de Goede 834a467af9 dix: Add GetCurrentClient helper
Request-handlers as registered in the requestVector array, always get
passed the clientPtr for the client which sent the request.
But the implementation of many request-handlers typically consists of
a generic handler calling implementation specific callbacks and / or
various helpers often multiple levels deep and in many cases the clientPtr
does not get passed to the callbacks / helpers.

This means that in some places where we would like to have access to the
current-client, we cannot easily access it and fixing this would require
a lot of work and often would involve ABI breakage.

This commit adds a GetCurrentClient helper which can be used as a
shortcut to get access to the clienPtr for the currently being processed
request without needing a lot of refactoring and ABI breakage.

Note using this new GetCurrentClient helper is only safe for code
which only runs from the main thread, this new variable MUST NOT be used
by code which runs from signal handlers or from the input-thread.

The specific use-case which resulted in the creation of this patch is adding
support for emulation of randr / vidmode resolution changes to Xwayland.
This emulation will not actually change the monitor resolution instead it
will scale any window with a size which exactly matches the requested
resolution to fill the entire monitor. The main use-case for this is
games which are hard-coded to render at a specific resolution and have
sofar relied on randr / vidmode to change the monitor resolution when going
fullscreen.

To make this emulation as robust as possible (e.g. avoid accidentally scaling
windows from other apps) we want to make the emulated resolution a per client
state. But e.g. the RRSetCrtc function does not take a client pointer; and is
a (used) part of the Xorg server ABI (note the problem is not just limited
to RRSetCrtc).

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2019-10-12 12:19:14 +02:00
Arthur Williams e693c9657f dix: Check for NULL spriteInfo in GetPairedDevice
There is a race when reseting the XServer that causes spriteInfo to be
NULL in GetPairedDevice resulting a segfault and subsequent crash. The
problem was noticed when opening a connection, creating master devices,
destroying master devices and closing the connection during testing.

Signed-off-by: Arthur Williams <taaparthur@gmail.com>
2019-10-06 12:18:13 -07:00
Adam Jackson 7d0e660e0e meson: Add dtrace support 2019-08-27 17:38:59 -04:00
Adam Jackson e0e051a392 dtrace: s/#if/#ifdef/ for XSERVER_DTRACE
No functional change, matches meson style.
2019-08-27 17:38:59 -04:00
Adam Jackson 7968d10fad dtrace: Move Xserver.d from dix/ to include/
dix/ is typically not in the include path, and this properly belongs in
include anyway since it's needed from os/ too.
2019-08-27 17:38:54 -04:00
Adam Jackson 4fa43fc513 dtrace: Remove Xserver-dtrace.h.in hack
This was a workaround for very old versions of dtrace(1) that didn't
support the -h switch. We no longer support such old OSes.
2019-08-27 15:43:50 -04:00
Matt Turner 61aa40aeb3 dix: Assert noPanoramiXExtension is false in PanoramiX code
When compiling with link time optimization, GCC thinks it's discovered
undefined behavior:

events.c: In function 'XineramaConfineCursorToWindow':
events.c:609:13: warning: iteration 2147483647 invokes undefined behavior [-Waggressive-loop-optimizations]
events.c:609:11: note: within this loop
events.c:605:49: warning: array subscript -1 is below array bounds of 'struct _Window *[16]' [-Warray-bounds]
events.c:606:31: warning: array subscript -1 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds]
events.c:610:39: warning: array subscript -2 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds]
events.c:617:38: warning: array subscript -2 is below array bounds of 'struct _Window *[16]' [-Warray-bounds]
events.c:619:35: warning: array subscript -2 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds]

This results from

    i = PanoramiXNumScreens - 1;

    RegionCopy(&pSprite->Reg1, &pSprite->windows[i]->borderSize);
    off_x = screenInfo.screens[i]->x;
    off_y = screenInfo.screens[i]->y;

where GCC believes that PanoramiXNumScreens might be 0. Unfortunately
GCC is just smart enough to be an annoyance because this case is not
actually possible: XineramaConfineCursorToWindow() is only called when
noPanoramiXExtension is false, and if noPanoramiXExtension is false then
PanoramiXNumScreens must be >1 (see PanoramiXExtensionInit()).

So, add an assert(!noPanoramiXExtension), which to my surprise provides
GCC with information even in release builds and lets GCC understand that
the code is not doing anything that is undefined behavior.

I chose this solution instead of the proposed assert(i >= 0) because the
same pattern occurs in CheckVirtualMotion() but is inside an
'if (!noPanoramiXExtension)' and does not generate any warnings.

Fixes: xorg/xserver#590
Signed-off-by: Matt Turner <mattst88@gmail.com>
2019-08-09 20:45:01 -07:00
Adam Richter 9d25408a59 assert(a && b) --> assert(a); assert(b)
Separate each statement of the form "assert(a && b);" into "assert(a);"
and "assert(b);" for more precise diagnostics, except for this clever
use in drmmode_display.c where it was used to pass a hint to developers:

	assert(num_infos <= 32 && "update return type");
2019-05-02 15:02:36 -07:00
Adam Jackson 6975807945 dix: Remove WindowRec::backStorage
This is only being set, never read.
2019-04-12 21:53:03 +00:00
Adam Jackson 0f477cc68b dix, composite: Optimize setting window backing store state
We hide CWBackingStore from the screen hook if nothing's actually
changing, which means compChangeWindowAttributes no longer needs to
compare the requested state with the present one.
2019-04-12 21:53:03 +00:00
Peter Hutterer d7b1753d44 dix: leave last.valuators alone on slave switch
Terms:
dev->last.valuator[] is the last value given to us by the driver
dev->valuator.axisVal[] is the last value sent to the client
dev->last.scroll[] is the abs value of the scroll axis as given by the driver,
        used for button emulation calculation (and the remainder)

This function updates the device's last.valuator state based on the current
master axis state. This way, relative motion continues fluidly when switching
between devices. Before mouse 2 comes into effect, it's valuator state is
updated to wherever the pointer currently is so the relative event applies on
top of that.

This can only work for x/y axes, all other axes aren't guaranteed to have the
same meaning and/or may not be present:
- xtest device: no valuator 2
- mouse: valuator 2 is horizontal scroll axis
- tablet: valuator 2 is pressure

Scaling the current value from the pressure range into the range for
horizontal scrolling makes no sense. And it causes scroll jumps:

- scroll down, last.valuator == axisVal == 20
- xdotool click 1, the XTest device doesn't have that valuator
- scroll up
  - updateSlaveDeviceCoords reset last.valuator to 0 (axisVal == 20)
  - DeviceClassesChangedEvent includes value 20 for the axis
  - event is processed, last.value changes from 0 to -1
  - axisVal is updated to -1, causing a jump of -21

The same applies when we switch from tablet to mouse wheel if the pressure
value is 0 on proximity out (basically guaranteed). So let's drop this code
altogether and only leave the scaling for the relative x/y motion.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-03-29 03:44:29 +00:00
Adam Jackson 3904216b01 dix: Outdent Unmap{Window,Subwindows} a bit
No functional change, just folding some conditionals together.
2019-03-11 17:02:28 +00:00
Olivier Fourdan c731165402 dix: cache ResourceClientBits() value
The `LimitClient` is set once and for all at startup, whereas the
function `ResourceClientBits()` which returns the client field offset
within the XID based on the value of `LimitClient` can be called
repeatedly.

Small optimization, cache the result of `ilog2()`, that saves running
the same loop over and over each time `ResourceClientBits()` is called.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2018-12-11 18:41:33 +00:00