summaryrefslogtreecommitdiffstats
path: root/video/out/x11_common.c
Commit message (Collapse)AuthorAgeFilesLines
* x11_common: unmaximize window on runtime geometry changenanahi2024-03-171-9/+6
| | | | | | | | | | | | | 8e793bde78f00fbb64223db30851c6d080c4abeb made that changing geometry while maximized has no effect until the window is unmaximazed. However, this behavior is inconsistent with setting window-scale on all of win32, wayland, and x11, which always unmaximizes the window and sets the window size. Since setting geometry is conceptually similar to setting window-scale (both change the window size), they should have the same behavior. If not fullscreen, unmaximize window on runtime geometry change to keep the behavior consistent with window-scale.
* x11_common: fix window x/y position when updating geometry on runtimenanahi2024-03-171-4/+8
| | | | | | | | | | | Currently, setting geometry on runtime only changes the window size but not the position. This is because reset_size is only set if the window size is changed, and vo_x11_highlevel_resize doesn't set the window position without force_window_position enabled. Fix this by setting the related flags and perform a window move when geometry is updated. Fixes 8e793bde78f00fbb64223db30851c6d080c4abeb.
* input: centralize VO draggingnanahi2024-03-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | Currently, VO dragging logic is hardcoded into each VO, where a left mouse button down event unconditionally begins dragging if the VO dragging test passes. This method is extremely unflexible as the VO has no knowledge of what is happening in the input system: while begin dragging with the second click of a doubleclick is undesired, it cannot determine whether a click is a double click or not because it's determined by the input system. The better way to do it is to handle it somewhere in the downstream consumers of the events instead, as they have more information to make this decision. The input system is the perfect place for this as the logic for checking doubleclick already exists. So just issue a begin-vo-dragging command if it detects a left mouse button down which isn't also a doubleclick in this case, and delete all hardcoded VO dragging logic in win32, x11, and wayland. Note that this solution hardcodes left mouse button down for now, but because the VO dragging is now centralized, it's possible to make more improvements, such as a deadzone mechanism to fix the conflict with MBTN_LEFT mouse bind.
* x11_common: implement VOCTRL_BEGIN_DRAGGINGnanahi2024-03-011-15/+29
| | | | | | | This allows begin-vo-dragging command to initialize a vo dragging request for x11. The last mouse button press event is used for _NET_WM_MOVERESIZE. The hard-coded left mouse button down trigger is scheduled to be removed in a later commit.
* x11: clean up hidpi-window-scale behaviorDudemanguy2024-02-241-14/+15
| | | | | | | | | | | | | | Several related things but in a nutshell makes it more like wayland. 1. Remove unneeded --hidpi-window-scale checks. The backend should always report the actual dpi value regardless of what this option says. 2. Remove dpi_scale factors from UNFS_WINDOW_SIZE VOCTRLs. It makes things more complicated and unintuitive for no reason. A window scale of 1 should mean 1. It annoyed a few years ago in #9437, and I agree with them (wayland was never implemented like this). 3. Change the dpi log messages to be more brief and remove the unneeded comments about prescaling.
* x11_common: handle window dragging in ButtonPress eventnanahi2024-02-211-25/+17
| | | | | | | | | | | | | | | Begin the _NET_WM_MOVERESIZE window dragging in ButtonPress event to match the behavior of win32 and wayland, simplify logic by dropping the win_drag_button1_down hack required by the old method, and fix a race condition described in commit 19f101db680f966a6e56035a16784541be390982, which happens when moving the mouse and releasing the button at the same time. The race condition can be easily triggered when using a touch screen (tested with libinput driver), where a tap is translated to MotionNotify, ButtonPress, MotionNotify, and ButtonRelease in sequence, with the last 2 events having the same timestamp. This has caused some window managers to not stop dragging after the ButtonRelease, resulting in window being stuck in dragging state after a single tap.
* x11_common: fix Xft.dpi detection ignoring --hidpi-window-scalesfan52024-02-121-3/+5
| | | | | closes #13466 fixes: 4b691641472b487831a0b0f7637d5355d79387cd
* x11_common: support --title-barnanahi2024-02-021-9/+13
| | | | | | | | | Some X11 window managers support controlling the title bar independently from other window decorations with _MOTIF_WM_HINTS. This allows hiding the title bar while keeping other decorations like the resizing borders. Let mpv respect the --title-bar option on X11 so --no-title-bar can hide the title bar only like on win32.
* x11_common: prefer Xft.dpi for HiDPI scalingnanahi2024-01-101-1/+41
| | | | | | | | Xft.dpi is much more widely used nowadays by GUI programs compared to the X11 screen DPI. This is the best we can get for a vendor-neutral scaling preference value under X11 in terms of adoption. If Xft.dpi isn't available, the X11 screen DPI is used as a fallback.
* x11_common: allow DPI scale in unit of 0.5nanahi2024-01-101-15/+24
| | | | | | | | ~144 DPI displays are pretty common and neither 1x nor 2x scales are the right size for it. Allow DPI scale in unit of 0.5 to fix this. Additionally, add a note about the current behavior of the API used to get the scale factor.
* x11_common: fix compose key handlingnanahi2023-12-101-1/+3
| | | | | | | | | | | Compose key doesn't function in X11 because XFilterEvent() isn't called, and XNInputStyle is set to a wrong value. This results in KeyPress events for the separate keyboard inputs in the compose key input sequence instead of the composed character, making it impossible to input certain characters which require compose key. Fix this by calling the required XFilterEvent() and set XNInputStyle to the correct value.
* input: add missing forward media keynanahi2023-12-061-1/+2
| | | | | | | | | XF86Back and XF86Forward are mostly used to navigate file and web browsers to go back/forward in history. XF86Forward isn't recognized right now, so add it. Because XF86AudioForward already takes the "FORWARD" name, rename the browse keys to GO_BACK and GO_FORWARD instead.
* various: replace some OOM handlingsfan52023-11-241-2/+1
| | | | | | We prefer to fail fast rather than degrade in unpredictable ways. The example in sub/ is particularly egregious because the code just skips the work it's meant to do when an allocation fails.
* vo: don't sleep 1ms always when requested time is in the pastKacper Michajłow2023-11-091-1/+1
| | | | | | | | | | | | | | Fixes a899e14b which changed clamp from 0 to 1 ms which effectivelly introduced 1ms sleep always, even if requested until_time_ns is in the past and should request 0 timeout. While at it also fix mp_poll wrapper to respect negative timeout which should mean infinite wait. Also keep the 37d6604 behaviour for very short timeouts, but round only the ones > 100us, anything else is 0. Fixes: a899e14b
* present_sync: only save as many entries as the swapchain depthDudemanguy2023-11-071-1/+1
| | | | | | Saving more than the swapchain depth is just wasteful. We can just save a copy of the vo_opts here and check the value whenever we're updating values.
* vo: replace max swapchain depth magic numberDudemanguy2023-11-071-1/+1
|
* present_sync: rename function to present_sync_update_valuesDudemanguy2023-11-061-1/+1
| | | | This had to have been a mistake. It was just confusing.
* present_sync: rewrite around linked listDudemanguy2023-11-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | When this was originally written, the queuing/list approach was deliberately removed since it adds more complication and xorg/wayland don't really use it anyway. In practice, you only really have one frame in flight with presentation timestamps. However, one slight annoyance is that the drm code has its own thing which is almost exactly the same and does its own calculations. Ideally, we'd port drm to this instead, but the implementation there takes into account N-frames in flight which probably does actually work. So we need to make present_sync smarter and be able to handle this. mpv does actually have its own linked list implementation already which is a good fit for this. mp_present becomes the list and each mp_present_entry has its own set of timestamps. During initialization, we create all the entries we need and then simply treat it like a queue during the lifecycle of the VO. When an entry is fully used (present_sync_get_info), then we remove it from the list, zero it out, and append it to the end for future use. This avoids needing to allocate memory on every frame (which is what drm currently does) and allows for a reasonable number of in flight frames at the same time as this should never grow to some obscene number. The nice thing is that current users of present_sync don't need to change anything besides the initialization step.
* vo: use mp_poll wrapper in wait_events when applicableDudemanguy2023-10-101-2/+3
| | | | | | | | | | On linux, several platforms poll for events over a fd. This has ms accuracy, but mpv's timer is in ns now so lots of precision is lost. We can use an mp_poll wrapper to use ppoll instead which takes a timespec directly with nanosecond precision. On systems without ppoll this falls back to old poll behavior. On wayland, we don't actually use this because ppoll completely messes up the event loop for some unknown reason.
* vo: change vo->driver->wait_events to nanosecondsDudemanguy2023-10-101-3/+3
| | | | | | | | | | | | In many cases, this is purely cosmetic because poll still only accepts microseconds. There's still a gain here however since pthread_cond_timedwait can take a realtime ts now. Additionally, 37d6604d70c8c594de2817db26356c4c950ac0fd changed the value added to timeout_ms in X11 and Wayland to ensure that it would never be 0 and rounded up. This was both incomplete, several other parts of the player have this same problem like drm, and not really needed. Instead the MPCLAMP is just adjusted to have a min of 1.
* vo: change vsync base to nanosecondsKacper Michajłow2023-09-291-1/+2
| | | | | There is no reason to use microseconds precision. We have precise timers all all relevant platforms.
* input: add missing keypad key definesChristoph Heinrich2023-08-251-5/+5
| | | | | | | | So far all the keypad keys except for `0` and `,` mapped to the same MP_KEY_* independent of numlock state, even though different key codes are received. Now all the alternative functions map to appropriate MP_KEY_* defines, with missing ones added.
* input: add new keys: Back, Tools, ZoomIn, ZoomOutJames Cuzella2023-08-231-0/+2
| | | | | | | | | | | | | | | | | These were the only keys missing to support mapping all keycodes on a [popular RF Remote][1] used with Linux HTPC apps. Note that X11/XWayland + xkbcomp still warns about keycodes > 255, due to the 8-bit limit in Xorg but `mpv` on Wayland is able to handle these. For X11 users, there are [a couple options][2]: - [Gianni Ceccarelli's patched `xf86-input-evdev`][3] - [Use udev hwdb to map scancodes to keycodes][4] [1]: https://www.mythtv.org/wiki/Air_mouse_rf_remote [2]: https://unix.stackexchange.com/a/436233/7688 [3]: https://www.thenautilus.net/SW/xf86-input-evdev/ [4]: https://wiki.archlinux.org/title/Map_scancodes_to_keycodes
* x11: set sizehint for fs-screen and fs-screen-nameDudemanguy2023-08-201-1/+5
| | | | | | | Without doing this, --fs --fs-screen=1 wouldn't actually end up on the desired screen since the sizehint was never sent. Also check the screen-name variants for an empty string as well so the option can properly "undo" itself (not sure if this has any practical effect).
* x11: remove xinerama and refactor window geometryDudemanguy2023-08-201-78/+69
| | | | | | | | | | | mpv mixes xinerama and randr usage together which gets kind of confusing and is also pretty stupid. Xinerama is completely unneccesary today since randr can do everything it can do and much more. Remove it. This reworks a lot of the window/geometry handling stuff to be centered completely around xrandr_display plus some other tweaks to the geometry handling. An important concept is that current_icc_screen is changed into current_screen and used more generously since it is useful for things besides just icc profiles.
* x11: require randr 1.4Dudemanguy2023-08-201-26/+19
| | | | | | There really is no reason to not just hard require randr 1.4. xorg added 1.4 support in 2012 and someone somehow using an xorg server older than that today surely has several other problems.
* x11: add --x11-wid-title optionDudemanguy2023-08-131-2/+3
| | | | | | | | | | This deliberately wasn't being done when mpv was embedded (fbccddb48b4c71c18300b092ef7a3860be2a659a). There are some applications that would benefit from mpv setting a title since they don't do so themselves (such as tabbed), but at the same time some others would probably rather not have this behavior (like smplayer). Add an option that allows an embedded mpv to set the title if the user wishes. Fixes #11528.
* x11_common: drop unnecessary NULL checkNRK2023-08-131-3/+1
| | | | similar to free(), XFree() is a no-op if argument is NULL
* x11_common: avoid unnecessary XUnmapWindow() callNRK2023-08-131-3/+1
| | | | | | | | XDestroyWindow() is called immediately after, which also unmaps window if needed. according to the manpage: > If the window specified by the w argument is mapped, it is unmapped > automatically.
* build: remove outdated generated directoryDudemanguy2023-07-311-4/+4
| | | | | | | | | | | | | | | | This only existed as essentially a workaround for meson's behavior and to maintain compatibility with the waf build. Since waf put everything in a generated subdirectory, we had to put make a subdirectory called "generated" in the source for meson so stuff could go to the right place. Well now we don't need to do that anymore. Move the meson.build files around so they go in the appropriate place in the subdirectory of the source tree and change the paths of the headers accordingly. A couple of important things to note. 1. mpv.com now gets made in build/player/mpv.com (necessary because of a meson limitation) 2. The macos icon generation path is shortened to TOOLS/osxbundle/icon.icns.inc.
* player: add --input-cursor-passthrough optionDudemanguy2023-07-041-1/+26
| | | | | | | | | | | | | Add an option for allowing pointer events to pass through the mpv window. This could be useful in cases where a user wants to display transparent images/video with mpv and interact with applications beneath the window. This commit implements this functionality for x11 and wayland. Note that whether or not this actually works likely depends on your window manager and/or compositor. E.g. sway ignores pointer events but the entire window becomes draggable when you float it (nothing under the mpv window receives events). Weston behaves as expected however so that is a compositor bug. Excuse the couple of completely unrelated style fixes (both were originally done by me).
* options: add no to drag-and-dropDudemanguy2023-07-011-1/+2
| | | | | Suggested by @sfan5. Naturally, "no" disables all drag and drop behavior.
* player: add drag-and-drop optionDudemanguy2023-06-121-3/+7
| | | | | | | | | | | Some platforms (wayland) apparently have a lot of trouble with drag and drop. The default behavior is still the same which is basically obeying what we get from the window manager/compositor, but the --drag-and-drop option allows forcibly overriding the drag and drop behavior. i.e. you can force it to always replace the playlist or append at the end. This only implements this in X11 and Wayland but in theory windows and macos could find this option useful (both hardcode the shift key for appending). Patches welcome.
* player: add --auto-window-resize optionDudemanguy2023-03-021-8/+13
| | | | | | | | | | | mpv's window resizing logic always automatically resized the window whenever the video resolution changed (i.e. advancing forward in a playlist). This simply introduces the option to make this behavior configurable. Every windowing backend would need to implement this behavior in their code since a reconfigure event must always be a resize. The params of the frame changed so you either have to resize the window to the new size of the params or make the params the same size as the window. This commit implements it for wayland, win32, and x11.
* various: drop unused #include "config.h"Thomas Weißschuh2023-02-201-1/+0
| | | | | | Most sources don't need config.h. The inclusion only leads to lots of unneeded recompilation if the configuration is changed.
* video/x11: replace sprintf usagesfan52023-01-121-1/+1
|
* video: replace sprintf usagesfan52023-01-121-1/+1
|
* vo: change vo_platform_init to boolDudemanguy2023-01-081-3/+3
| | | | | | | | There's several functions that are used for initializing mpv on a certain platform (x11, wayland, etc.). These currently are all int, but they actually return 1 and 0 like a boolean. This gets a bit confusing because actual vo preinit functions return 0 and -1 instead. Just make these all bool instead and return true/false to make it clearer.
* x11: add modesetting to the xpresent whitelistSultan Alsawaf2022-12-271-1/+2
| | | | | | | | | | | | | | | | Since the modesetting driver now has TearFree support with integration into xpresent, it's important that xpresent is used with the modesetting driver to get the correct vsync timing when a frame is delayed by one vblank interval due to a pending page-flip enqueued by a different entity. The modesetting driver ensures that the xpresent extension reports the correct presentation timing when TearFree is used; mpv just needs to listen to it. Add the modesetting driver to the xpresent whitelist so mpv can get the correct presentation completion timing when modesetting TearFree is used. This is also helpful for when xpresent performs page flips directly in the modesetting driver and a natural delay in the display pipeline causes a page flip to be delayed by one vblank interval or more.
* player: add window-id propertyNRK2022-12-051-0/+6
| | | | | | | | | | | | | | | | | | | | | currently only supported on x11. one practical use-case of this is wanting to embed something (such as dmenu) into the mpv window to use as a menu/selection. there might be other use-cases as well (e.g doing some shenanigans with `xdotool` or whatnot). it's currently possible to: * listen for 'current-window-scale' change (to check if the window has been created or not) * call an external tool like `xdo` or `xdotool` and grab the xid from mpv's pid. however it adds unnecessary dependency on external tools when mpv is fully capable of easily providing this information. closes: #10918
* player: add --force-render optionDudemanguy2022-11-151-1/+2
| | | | | | | | mpv has an internal optimization on a couple of platforms where it will not render any frames if the window is minimized or hidden. There's at least once possible use case for wanting to force a render anyway (screensharing with pipeware) so let's just add a simple switch for this that always forces mpv to render. Closes #10846.
* wayland, x11: fix possibly unsafe bstr usagesfan52022-11-101-2/+2
| | | | | | In practice this never led to any issues due to implementation details of bstr_sanitize_utf8_latin1, but there's no guarantee that a bstr is correctly null-terminated.
* x11: fix --on-all-workspaces optionodnar-dev2022-10-111-13/+34
| | | | mpv set _NET_WM_DESKTOP to 0xFFFFFFFF, which behaves differently with each window manager. Instead, set the window property to STICKY, and let the window managers deal with it.
* x11: fix a couple of memory leaksDudemanguy2022-10-081-0/+2
| | | | | | | | | | | Managed to go completely unnoticed for months (who was the bad person that introduced these*). Fairly self-explanatory. After getting ProviderInfo from randr, we need to free it. The other one is pretty bad because it leaked every frame (ouch). It turns out that you're supposed to free any event data after you cast a generic event to an XGenericEventCookie. Free that as well. *: It was me.
* x11: add support for F13-F24 keysThomas Weißschuh2022-09-021-0/+4
|
* x11: fix display-{width,height} calculationDudemanguy2022-08-141-3/+9
| | | | | | | | | | | | Unexpectedly, x11->screenrc actually doesn't update with randr events. In a multimonitor configuration it could easily be wrong depending on the user's layout. While it's tempting to modify the logic so screenrc changes with randr events, this rectangle is currently used everywhere and as far as we know, this pretty much works fine. Instead, just loop over the randr displays that we have and select it if it overlaps with the winrc. This follows the same logic as the fps selection in the case of the mpv window overlapping multiple monitors (the last one is selected).
* x11: avoid XPresent API calls when it's not neededDudemanguy2022-06-221-7/+21
| | | | | | | | | | | This commit kind of mixes several related things together. The main thing is to avoid calling any XPresent functions or internal functions related to presentation when the feature is not auto-whitelisted or enabled by the user. Internally rework this so it all works off of a use_present bool (have_present is eliminated because having a non-zero present_code covers exactly the same thing) and make sure it updates on runtime. Finally, put some actual logging in here whenever XPresent is enabled/disabled. Fixes #10326.
* x11: add --x11-present optionDudemanguy2022-06-221-3/+5
| | | | | | | | | | | With the recent addition of the libxpresent, it should improve frame timings for most users. However, there were known cases of bad behavior (Nvidia) which lead to a construction of a whitelist instead of just enabling this all the time. Since there's no way to predict whatever combination of hardware/drivers/etc. may work correctly, just give users an option to switch the usage of xorg's presentation statistics on/off. The default value, auto, works like before (basically, Mesa drivers and no Nvidia are allowed), but now one can force it on/off if needed.
* x11: add nouveau to the xpresent whitelistDudemanguy2022-06-221-1/+3
| | | | | A user noted that this worked correctly (i.e. vsync jitter of 0) so go ahead and add it here as a safe driver for xpresent to use.
* x11: correct provider detection logicDudemanguy2022-06-211-2/+2
| | | | | | | | | | | | The old logic always reset the x11->has_mesa/has_nvidia values on every loop through the provider. This meant that it would always just match whatever the last provider happened to be. So in the case of a dual GPU system, if nvidia was the very first provider and the integrated intel/amd card was the second (in practice, this is probably mostly the other way around), then mpv would set has_mesa to true and has_nvidia to false and thus try to use presentation. This is not the intended behavior. Just rework this by also checking x11->has_mesa/has_nvidia in the loop so a true value from the previous iteration is preserved.
* x11: replace strcasestr usage with bstrDudemanguy2022-06-191-6/+8
| | | | | strcasestr is a GNU extension, but we can just use bstr instead to do the same thing.
* x11: support xorg present extensionDudemanguy2022-06-191-0/+33
| | | | | | | | | | | | | | | | | | | | | |