1 /*
2  * This file is part of mpv.
3  *
4  * mpv is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * mpv is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with mpv.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MPLAYER_X11_COMMON_H
19 #define MPLAYER_X11_COMMON_H
20 
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 
26 #include "common/common.h"
27 #include "osdep/atomic.h"
28 
29 #include "config.h"
30 #if !HAVE_GPL
31 #error GPL only
32 #endif
33 
34 struct vo;
35 struct mp_log;
36 
37 #define MAX_DISPLAYS 32 // ought to be enough for everyone
38 
39 struct xrandr_display {
40     struct mp_rect rc;
41     double fps;
42     char *name;
43     bool overlaps;
44     int atom_id;
45 };
46 
47 struct vo_x11_state {
48     struct mp_log *log;
49     struct input_ctx *input_ctx;
50     struct m_config_cache *opts_cache;
51     struct mp_vo_opts *opts;
52     Display *display;
53     int event_fd;
54     int wakeup_pipe[2];
55     Window window;
56     Window rootwin;
57     Window parent;  // embedded in this foreign window
58     int screen;
59     int display_is_local;
60     int ws_width;
61     int ws_height;
62     int dpi_scale;
63     struct mp_rect screenrc;
64     char *window_title;
65 
66     struct xrandr_display displays[MAX_DISPLAYS];
67     int num_displays;
68     int current_icc_screen;
69 
70     int xrandr_event;
71 
72     bool screensaver_enabled;
73     bool dpms_touched;
74     double screensaver_time_last;
75 
76     XIM xim;
77     XIC xic;
78     bool no_autorepeat;
79 
80     Colormap colormap;
81 
82     int wm_type;
83     bool window_hidden; // the window was mapped at least once
84     bool pseudo_mapped; // not necessarily mapped, but known window size
85     int fs;     // whether we assume the window is in fullscreen mode
86 
87     bool mouse_cursor_visible; // whether we want the cursor to be visible (only
88                                // takes effect when the window is focused)
89     bool mouse_cursor_set; // whether the cursor is *currently* *hidden*
90     bool has_focus;
91     long orig_layer;
92 
93     // Current actual window position (updated on window move/resize events).
94     struct mp_rect winrc;
95     double current_display_fps;
96 
97     int pending_vo_events;
98 
99     // last non-fullscreen extends (updated on fullscreen or reinitialization)
100     struct mp_rect nofsrc;
101 
102     /* Keep track of original video width/height to determine when to
103      * resize window when reconfiguring. Resize window when video size
104      * changes, but don't force window size changes as long as video size
105      * stays the same (even if that size is different from the current
106      * window size after the user modified the latter). */
107     int old_dw, old_dh;
108     /* Video size changed during fullscreen when we couldn't tell the new
109      * size to the window manager. Must set window size when turning
110      * fullscreen off. */
111     bool size_changed_during_fs;
112     bool pos_changed_during_fs;
113 
114     /* The geometry/autofit option was changed while the window was maximized.
115      * Wait until the state changes to resize. */
116     bool pending_geometry_change;
117 
118     XComposeStatus compose_status;
119 
120     /* XShm stuff */
121     int ShmCompletionEvent;
122     /* Number of outstanding XShmPutImage requests */
123     /* Decremented when ShmCompletionEvent is received */
124     /* Increment it before XShmPutImage */
125     int ShmCompletionWaitCount;
126 
127     /* drag and drop */
128     Atom dnd_requested_format;
129     Atom dnd_requested_action;
130     Window dnd_src_window;
131 
132     /* dragging the window */
133     bool win_drag_button1_down;
134 
135     Atom icc_profile_property;
136 };
137 
138 int vo_x11_init(struct vo *vo);
139 void vo_x11_uninit(struct vo *vo);
140 void vo_x11_check_events(struct vo *vo);
141 bool vo_x11_screen_is_composited(struct vo *vo);
142 bool vo_x11_create_vo_window(struct vo *vo, XVisualInfo *vis,
143                              const char *classname);
144 void vo_x11_config_vo_window(struct vo *vo);
145 int vo_x11_control(struct vo *vo, int *events, int request, void *arg);
146 void vo_x11_wakeup(struct vo *vo);
147 void vo_x11_wait_events(struct vo *vo, int64_t until_time_us);
148 
149 void vo_x11_silence_xlib(int dir);
150 
151 bool vo_x11_is_rgba_visual(XVisualInfo *v);
152 
153 #endif /* MPLAYER_X11_COMMON_H */
154