Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add defines at configure time for wayland protocol interface versions #13993

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions TOOLS/wayland-interface-parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""
Simple script to parse out interface names and version in wayland protocols
for meson.
"""

#
# This file is part of mpv.
#
# mpv is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
#

import re
import sys

def parse_interface(line):
line = re.sub('[<">\n]', '', line.strip())
line = line.replace("interface name", "interface_name")
split = line.split()
interface = ""
for entry in split:
key, value = entry.split("=")
if key == "interface_name":
interface += value.upper() + "_VERSION "
if key == "version":
interface += value
return interface

if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <file>")
sys.exit(1)

interfaces = []
with open(sys.argv[1], 'r') as f:
for line in f:
if "interface name=" in line:
interfaces.append(parse_interface(line))
sys.stdout.write(','.join(interfaces))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, but there is mix of " and ' usage, make it use one of them.

2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ project('mpv',

build_root = meson.project_build_root()
source_root = meson.project_source_root()
conf_data = configuration_data()
python = find_program('python3')

# ffmpeg
Expand Down Expand Up @@ -1660,7 +1661,6 @@ endif


# Set config.h
conf_data = configuration_data()
conf_data.set_quoted('CONFIGURATION', configuration)
conf_data.set_quoted('DEFAULT_DVD_DEVICE', dvd_device)
conf_data.set_quoted('DEFAULT_CDROM_DEVICE', cd_device)
Expand Down
8 changes: 8 additions & 0 deletions video/out/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ endif

foreach p: protocols
xml = join_paths(p)

wayland_interface_parse = find_program(join_paths(tools_directory, 'wayland-interface-parse.py'))
interfaces = run_command(wayland_interface_parse, xml, check: true).stdout().split(',')
foreach interface: interfaces
split = interface.split()
conf_data.set(split[0], split[1].to_int())
endforeach

wl_protocols_source += custom_target(xml.underscorify() + '_c',
input: xml,
output: '@[email protected]',
Expand Down
2 changes: 1 addition & 1 deletion video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ static void registry_handle_add(void *data, struct wl_registry *reg, uint32_t id
}

if (!strcmp(interface, xdg_wm_base_interface.name) && found++) {
ver = MPMIN(ver, 6); /* Cap at 6 in case new events are added later. */
ver = MPMIN(ver, XDG_WM_BASE_VERSION);
wl->wm_base = wl_registry_bind(reg, id, &xdg_wm_base_interface, ver);
xdg_wm_base_add_listener(wl->wm_base, &xdg_wm_base_listener, wl);
}
Expand Down