Fix typo in header guard.

Signed-off-by: Thomas Klausner <wiz@NetBSD.org>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
dix: scale y back instead of x up when pre-scaling coordinates

The peculiar way we handle coordinates results in relative coordinates on
absolute devices being added to the last value, then that value is mapped to
the screen (taking the device dimensions into account). From that mapped
value we get the final coordinates, both screen and device coordinates.

To avoid uneven scaling on relative coordinates, they are pre-scaled by
screen ratio:resolution:device ratio factor before being mapped. This
ensures that a circle drawn on the device is a circle on the screen.

Previously, we used the ratio to scale x up. Synaptics already does its own
scaling based on the resolution and that is done by scaling y down by the
ratio. So we can remove the code from the driver and get approximately the
same behaviour here.

Minor ABI bump, so we can remove this from synaptics.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Emmanuel Benisty <benisty.e@gmail.com>
Merge remote-tracking branch 'alanc/master'
Allow DDX to provide a main()

XQuartz already conditionally renames main() as dix_main() so it can provide
it's own main().  This isn't the ideal way of doing this, as it prevents libdix
built this way from being useful with any other DDX.

So instead, always name that function dix_main(), and also provide a stub main()
which just calls dix_main(), which can be overriden in the DDX.

Add a main() to XWin (XQuartz already has one, of course).

It's no longer neccessary to link XWin and XQuartz with libmain.

v2: Remove unneeded stub main hw/xwin/InitOutput.c

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Improve WM_ENDSESSION handling using separate messaging window thread

Currently, WM_ENDSESSION just calls GiveUp() to set the DE_TERMINATE flag. But
for the X server to exit cleanly, we also need the X server dispatch loop to be
unblocked so it can notice that DE_TERMINATE has been set and exit, removing
it's lock file and any unix domain socket.

It appears that the system will terminate the process when the last UI thread in
that process returns from processing WM_ENDSESSION for the last top-level
window.

Since WM_ENDSESSION appears to sent by the system via SendMessage()
(synchronously) and the wndproc is called to process it in the message thread
for that window (the X server thread), we can't easily terminate the X server
dispatch loop from inside the WM_ENDSESSION message processing.

So, create a messaging window, a hidden, top-level window, with a separate
thread to catch this message, and process it by calling GiveUp() and then
blocking on a mutex until the X server dispatch loop exits.

Also, notice when this is a shutdown cancel WM_ENDSESSION message and take no
action.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: _NET_WM_STATE is ATOM[] not ATOM

_NET_WM_STATE is ATOM[] not ATOM, a list of window state hints, so check all of
the atoms, not just the first one

See EWMH specifcation, section "Application Window Properties"

v2: Actually use [] on the returned atom data

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove an extra '\n' from some log messages

Remove an extra '\n' from internal client IOError log messages

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Consider left and right modifier keys independently on gaining focus

Handle left and right ctrl and shift keys independently

Assume that all modifiers are cleared when all keys are released on focus lost,
as internalKeyState doesn't record which modifier key was pressed.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Change winTranslateKey() to return it's result as it's return value

Change winTranslateKey() to return it's result as it's return value, and change
it's uses as well.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove unneeded WM_XBUTTON message defines

Remove unneeded WM_XBUTTON message defines, they have been provided by w32api
for a long time now.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Map extra mouse buttons 1 and 2 to X buttons 8 and 9

Map extra mouse buttons 1 and 2 to X buttons 8 and 9, as conventional, leaving X
buttons 6 and 7 for tilt wheel.

Also add button labels for buttons 6, 7, 8 and 9 and change btn_labels in from a
dynamic allocation to a fixed one of the required size for all the labels we
use.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Handle WM_MOUSEHWHEEL

Handle WM_MOUSEHWHEEL tilt wheel messages, similarly to WM_MOUSEWHEEL scroll
wheel messages, to generate X button 6 and 7 presses and releases.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Avoid a null dereference if CreateDIBSection() fails in NetWMToWinIconAlpha()

Avoid a null dereference of DIB_pixels if CreateDIBSection() fails in
NetWMToWinIconAlpha()

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
configure.ac: Check for python at configure time when building XWin with AIGLX

Check for python at configure time when building XWin with AIGLX, it's used to
generate the wrapper code for native GL functions.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Remove obsolete WIN_XEVENTS_SHUTDOWN

Remove obsolete WIN_XEVENTS_SHUTDOWN.  This event is never generated.

(I think the idea was to listen for WM_DELETE_WINDOW, but that's not a very
useful thing to do for a hidden window.)

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
hw/xwin: Fix possible crash in winMultiWindowGetClassHint

Fix a possible crash in winMultiWindowGetClassHint() when an application doesn't
null terminate the WM_CLASS property class name (which is an ICCCM conformance
bug in the application)

(Reported for running the contiki cooja simulator in multiwindow mode, although
it seems that many Java clients may have this problem, see [1])

Based on a patch by Marc Haesen.

v2: Avoid using strnlen() which is missing on MinGW
v3: Align with Xming patch

[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6961123

Signed-off-by: Colin Harrison <colin.harrison@virgin.net>
Reviewed-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
Reviewed-by: Jon TURNEY <jon.turney@dronecode.org.uk>
hw/xwin: Fix numerous 64-bit format/type cast issues with debug printing of pointers

Numerous pieces of debug output cast a pointer to an int and then use a "%08x"
printf format.

Use "%p" format for 64-bit portability.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
dix: check the xi2mask, not the grab type for touch listeners

grab->type is only non-zero for passive grabs. We're checking an active grab
here, so we need to check if the touch mask is set on the grab.

Test case: grab the device, then start two simultaneous touches. The
grabbing client won't see the second touchpoints because grab->type is 0
and the second touch is not an emulating pointer.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
dix: set the valuator mask to ensure XI 1.x events have data

XI 1.x only allows for first + num valuators, so if a device sends data for
valuators 0 and 2+ only (i.e. valuator 1 is missing) we still need to get
the data for that from somewhere.
XI 1.x uses the hack of an unset valuator mask to get the right coordinates,
i.e. we set the value but don't set the mask for it so XI2 events have the
right mask.

For an absolute device in relative mode, this broke in b28a1af55cf, the
value was now always 0. This wasn't visible on the cursor, only in an XI 1.x
client. The GIMP e.g. sees jumps to x/0 every few events.

Drop the condition introduced in b28a1af55cf, data in valuators is always
absolute, regardless of the mode.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
xfree86: detach scanout pixmaps when detaching output GPUs

Commit 8f4640bdb9d3988148e09a08d2c7e3bab1d538d6 fixed a bit of a
chicken-and-egg problem by detaching GPU screens when their providers
are destroyed, which happens before CloseScreen is called.  However,
this created a new problem: the GPU screen tears down its RandR crtc
objects during CloseScreen and if one of them is active, it tries to
detach the scanout pixmap then.  This crashes because
RRCrtcDetachScanoutPixmap tries to get the master screen's screen
pixmap, but crtc->pScreen->current_master is already NULL at that
point.

It doesn't make sense for an unbound GPU screen to still be scanning
out its former master screen's pixmap, so detach them first when the
provider is destroyed.

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>