aboutsummaryrefslogtreecommitdiffhomepage
path: root/video/out/x11_common.h
blob: 812c309afe3f33b1c75d8f4fcf4dde51049b422b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * This file is part of mpv.
 *
 * mpv is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * mpv is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with mpv.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MPLAYER_X11_COMMON_H
#define MPLAYER_X11_COMMON_H

#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include "osdep/atomics.h"
#include "osdep/semaphore.h"

#include "common/common.h"

struct vo;
struct mp_log;

#define MAX_DISPLAYS 32 // ought to be enough for everyone

struct xrandr_display {
    struct mp_rect rc;
    double fps;
    char *name;
    bool overlaps;
};

struct vo_x11_state {
    struct mp_log *log;
    struct input_ctx *input_ctx;
    Display *display;
    Window window;
    Window rootwin;
    Window parent;  // embedded in this foreign window
    int screen;
    int display_is_local;
    int ws_width;
    int ws_height;
    struct mp_rect screenrc;
    char *window_title;

    struct xrandr_display displays[MAX_DISPLAYS];
    int num_displays;

    int xrandr_event;

    bool screensaver_enabled;
    bool dpms_touched;
    double screensaver_time_last;
    pthread_t screensaver_thread;
    bool screensaver_thread_running;
    sem_t screensaver_sem;
    atomic_bool screensaver_terminate;

    XIM xim;
    XIC xic;
    bool no_autorepeat;

    Colormap colormap;

    int wm_type;
    bool window_hidden; // the window was mapped at least once
    bool pseudo_mapped; // not necessarily mapped, but known window size
    int fs;     // whether we assume the window is in fullscreen mode

    bool mouse_cursor_hidden;
    long orig_layer;

    // Current actual window position (updated on window move/resize events).
    struct mp_rect winrc;
    double current_display_fps;

    int pending_vo_events;

    // last non-fullscreen extends (updated on fullscreen or reinitialization)
    struct mp_rect nofsrc;

    /* Keep track of original video width/height to determine when to
     * resize window when reconfiguring. Resize window when video size
     * changes, but don't force window size changes as long as video size
     * stays the same (even if that size is different from the current
     * window size after the user modified the latter). */
    int old_dw, old_dh;
    /* Video size changed during fullscreen when we couldn't tell the new
     * size to the window manager. Must set window size when turning
     * fullscreen off. */
    bool size_changed_during_fs;
    bool pos_changed_during_fs;

    XComposeStatus compose_status;

    /* XShm stuff */
    int ShmCompletionEvent;
    /* Number of outstanding XShmPutImage requests */
    /* Decremented when ShmCompletionEvent is received */
    /* Increment it before XShmPutImage */
    int ShmCompletionWaitCount;

    /* drag and drop */
    Atom dnd_requested_format;
    Atom dnd_requested_action;
    Window dnd_src_window;

    /* dragging the window */
    bool win_drag_button1_down;

    Atom icc_profile_property;
};

int vo_x11_init(struct vo *vo);
void vo_x11_uninit(struct vo *vo);
int vo_x11_check_events(struct vo *vo);
bool vo_x11_screen_is_composited(struct vo *vo);
bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
                             const char *classname);
void vo_x11_config_vo_window(struct vo *vo);
int vo_x11_control(struct vo *vo, int *events, int request, void *arg);

void vo_x11_silence_xlib(int dir);

#endif /* MPLAYER_X11_COMMON_H */