Mercurial > minori
changeset 342:adb79bdde329
dep/animone: fix tons of issues
for example, the window ID stuff was just... completely wrong. since we're
supporting multiple different window systems, it *has* to be a union rather
than just a single integer type. HWND is also not a DWORD, it's a pointer(!),
so now it's stored as a std::uintptr_t.
(this probably breaks things)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 20 Jun 2024 03:03:05 -0400 |
parents | 052ec053ee37 |
children | 1faa72660932 |
files | configure.ac dep/animone/Makefile.am dep/animone/configure.ac dep/animone/include/animone.h dep/animone/include/animone/media.h dep/animone/include/animone/player.h dep/animone/include/animone/types.h dep/animone/include/animone/util/win32.h dep/animone/src/a11y/win32.cc dep/animone/src/fd/win32.cc dep/animone/src/win/quartz.cc dep/animone/src/win/win32.cc dep/animone/src/win/x11.cc dep/anitomy/configure.ac dep/pugixml/configure.ac rc/sys/win32/dark/dark.qss |
diffstat | 16 files changed, 88 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Wed Jun 19 23:21:19 2024 -0400 +++ b/configure.ac Thu Jun 20 03:03:05 2024 -0400 @@ -100,6 +100,8 @@ dnl Check for windres AC_CHECK_TOOL([WINDRES], [windres]) AC_SUBST([WINDRES]) + + AC_DEFINE([ANIMONE_STATIC], [1], [stupid windows thing]) elif test "x$build_osx" = "xyes"; then AC_DEFINE([MACOSX]) else
--- a/dep/animone/Makefile.am Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/Makefile.am Thu Jun 20 03:03:05 2024 -0400 @@ -29,7 +29,7 @@ if BUILD_WIN files_win = src/a11y/win32.cc src/fd/win32.cc src/win/win32.cc src/util/win32.cc -libs_win = -lole32 -luuid +libs_win = -lole32 -loleaut32 -luuid endif if BUILD_OSX @@ -83,8 +83,8 @@ libanimone_la_CPPFLAGS = -I$(top_srcdir)/include $(DEFS) libanimone_la_CXXFLAGS = -std=c++17 $(cflags_osx) $(cflags_x11) $(cflags_wayland) -libanimone_la_LDFLAGS = -version-info 0:0:0 $(ldflags_osx) +libanimone_la_LDFLAGS = -no-undefined -version-info 0:0:0 $(ldflags_osx) -libanimone_la_LIBADD = $(libs_win) $(libs_wayland) $(libs_x11) $(libs_osx) $(libs_libutil) $(libs_libkvm) +libanimone_la_LIBADD = $(libs_win) $(libs_wayland) $(libs_x11) $(libs_osx) $(libs_freebsd) $(libs_openbsd) ACLOCAL_AMFLAGS = -I m4
--- a/dep/animone/configure.ac Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/configure.ac Thu Jun 20 03:03:05 2024 -0400 @@ -1,4 +1,4 @@ -AC_INIT([animone], [2.0.0]) +AC_INIT([animone], [0.2.0]) AC_CANONICAL_HOST @@ -12,7 +12,7 @@ AC_PROG_CXX AM_PROG_AR -LT_INIT +LT_INIT([win32-dll]) build_win32=no build_osx=no @@ -70,7 +70,6 @@ AM_CONDITIONAL([BUILD_LINUX], [test "x$build_linux" = "xyes"]) AM_CONDITIONAL([BUILD_FREEBSD], [test "x$build_libutil" = "xyes"]) AM_CONDITIONAL([BUILD_OPENBSD], [test "x$build_kvm" = "xyes"]) -AM_CONDITIONAL([BUILD_BSD], [test "x$build_bsd" = "xyes"]) AM_CONDITIONAL([BUILD_XCB], [test "x$build_x11" = "xyes"])
--- a/dep/animone/include/animone.h Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/include/animone.h Thu Jun 20 03:03:05 2024 -0400 @@ -9,27 +9,27 @@ namespace animone { -struct Process { +struct ANIMONE_API Process { internal::pid_t pid = 0; /* platform-dependent PID */ ExecutablePlatform platform = ExecutablePlatform::Unknown; /* platform of the executable */ std::string comm; /* the full filename of the executable */ }; -struct Window { - std::uint32_t id = 0; /* platform-dependent window id */ +struct ANIMONE_API Window { + internal::wid_t id = {0}; /* union of window IDs. depends on the platform which one is correct */ WindowPlatform platform = WindowPlatform::Unknown; /* platform of the window */ std::string class_name; /* class name on win32 and x11, bundle ID on macos */ std::string text; /* title bar text if available */ }; -struct Result { +struct ANIMONE_API Result { Player player; Process process; Window window; /* has nothing under process mode */ std::vector<Media> media; }; -bool GetResults(const std::vector<Player>& players, std::vector<Result>& results); +ANIMONE_API bool GetResults(const std::vector<Player>& players, std::vector<Result>& results); } // namespace animone
--- a/dep/animone/include/animone/media.h Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/include/animone/media.h Thu Jun 20 03:03:05 2024 -0400 @@ -1,6 +1,8 @@ #ifndef ANIMONE_ANIMONE_MEDIA_H_ #define ANIMONE_ANIMONE_MEDIA_H_ +#include "animone/types.h" + #include <chrono> #include <functional> #include <string> @@ -19,12 +21,12 @@ Url }; -struct MediaInfo { +struct ANIMONE_API MediaInfo { MediaInfoType type = MediaInfoType::Unknown; std::string value; }; -struct Media { +struct ANIMONE_API Media { std::vector<MediaInfo> information; };
--- a/dep/animone/include/animone/player.h Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/include/animone/player.h Thu Jun 20 03:03:05 2024 -0400 @@ -1,6 +1,8 @@ #ifndef ANIMONE_ANIMONE_PLAYER_H_ #define ANIMONE_ANIMONE_PLAYER_H_ +#include "animone/types.h" + #include <string> #include <vector> #include <map> @@ -32,7 +34,7 @@ WebBrowser // unused }; -struct Player { +struct ANIMONE_API Player { PlayerType type = PlayerType::Default; std::string name; std::string window_title_format; @@ -41,8 +43,8 @@ std::vector<Strategy> strategies; }; -bool ParsePlayersData(const std::string& data, std::vector<Player>& players); -bool ParsePlayersFile(const std::string& path, std::vector<Player>& players); +ANIMONE_API bool ParsePlayersData(const std::string& data, std::vector<Player>& players); +ANIMONE_API bool ParsePlayersFile(const std::string& path, std::vector<Player>& players); } // namespace animone
--- a/dep/animone/include/animone/types.h Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/include/animone/types.h Thu Jun 20 03:03:05 2024 -0400 @@ -1,20 +1,43 @@ #ifndef ANIMONE_ANIMONE_TYPES_H_ #define ANIMONE_ANIMONE_TYPES_H_ -/* define this as unsigned long (DWORD) on win32 so we - * don't force the user to include <windows.h> or <IntBase.h> */ -#ifdef _WIN32 -# include <cstdint> +#include <cstdint> + +/* windows is so annoying */ +#ifdef ANIMONE_STATIC +# define ANIMONE_API +#else +# ifdef _WIN32 +# ifdef DLL_EXPORT +# define ANIMONE_API __declspec(dllexport) +# else +# define ANIMONE_API __declspec(dllimport) +# endif +# else +# define ANIMONE_API +# endif +#endif + +/* FIXME configure this in autoconf */ +#ifndef _WIN32 +#include <sys/types.h> +#endif namespace animone::internal { + +#ifdef _WIN32 using pid_t = std::uint32_t; -} #else -/* <sys/types.h> shouldn't be that big, right? */ -# include <sys/types.h> -namespace animone::internal { using pid_t = ::pid_t; -} #endif +/* different window systems have different sized IDs */ +union ANIMONE_API wid_t { + std::uintptr_t win32; + std::int64_t quartz; // FIXME is this correct? + std::uint32_t x11; +}; + +} + #endif // ANIMONE_ANIMONE_TYPES_H_
--- a/dep/animone/include/animone/util/win32.h Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/include/animone/util/win32.h Thu Jun 20 03:03:05 2024 -0400 @@ -23,10 +23,6 @@ std::string ToUtf8String(const UNICODE_STRING& string); std::wstring ToWstring(const std::string& string); -/* XXX can this stuff be moved to fd/win32.cc? */ -bool IsSystemDirectory(const std::string& path); -bool IsSystemDirectory(std::wstring path); - } // namespace animone::internal::win32 #endif // ANIMONE_ANIMONE_UTIL_WIN32_H_ \ No newline at end of file
--- a/dep/animone/src/a11y/win32.cc Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/src/a11y/win32.cc Thu Jun 20 03:03:05 2024 -0400 @@ -1,12 +1,14 @@ #include <functional> #include <string> #include <vector> +#include <memory> #include <windows.h> #include <uiautomation.h> #include "animone/a11y.h" #include "animone/a11y/win32.h" +#include "animone/util/win32.h" namespace animone::internal::win32 { @@ -25,9 +27,9 @@ template <typename T> struct ComInterfaceDeleter { - static_assert(std::is_base_of<IUnknown, T>::value, "Invalid COM interface"); - using pointer = T*; - void operator()(pointer p) const { if (p) p->Release(); } + static_assert(std::is_base_of<IUnknown, T>::value, "Invalid COM interface"); + using pointer = T*; + void operator()(pointer p) const { if (p) p->Release(); } }; template <typename T> @@ -234,7 +236,7 @@ if (!InitializeUIAutomation()) return false; - ComInterface<Element> parent(GetElementFromHandle(hwnd)); + ComInterface<Element> parent(GetElementFromHandle(reinterpret_cast<HWND>(window.id.win32))); if (!parent) return false;
--- a/dep/animone/src/fd/win32.cc Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/src/fd/win32.cc Thu Jun 20 03:03:05 2024 -0400 @@ -12,6 +12,7 @@ * then they're pretty much forced to keeping this the same anyway. */ #include "animone/fd/win32.h" +#include "animone/util.h" #include "animone.h" #include "animone/util/win32.h" @@ -19,6 +20,7 @@ #include <string> #include <unordered_map> #include <vector> +#include <optional> #include <fileapi.h> #include <handleapi.h> @@ -141,19 +143,9 @@ /* ------------------------------------------------------------------- */ static bool GetSystemDirectory(std::wstring& str) { - PWSTR path_wch; - - if (FAILED(::SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, &path_wch))) - return false; - - str.assign(path_wch); + str.assign(MAX_PATH, '\0'); - ::CoTaskMemFree(path_wch); - return true; -} - -static bool IsSystemDirectory(const std::string& path) { - return IsSystemDirectory(ToWstring(path)); + return SUCCEEDED(::SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, &str.front())); } static bool IsSystemDirectory(std::wstring path) { @@ -168,6 +160,10 @@ return path.find(windir) == 4; } +static bool IsSystemDirectory(const std::string& path) { + return IsSystemDirectory(ToWstring(path)); +} + static bool IsFileHandle(HANDLE handle, unsigned short object_type_index) { /* this is filled in at runtime because it's not guaranteed to be (and isn't) * constant between different versions of Windows */ @@ -179,7 +175,7 @@ /* XXX what? */ return true; } else if (GetHandleType(handle) == L"File") { - file_type_index.reset(object_type_index); + file_type_index = object_type_index; return true; } @@ -212,7 +208,7 @@ /* ------------------------------------------------------------------- */ -static std::string GetProcessPath(DWORD process_id) { +static bool GetProcessPath(DWORD process_id, std::string& path) { // If we try to open a SYSTEM process, this function fails and the last error // code is ERROR_ACCESS_DENIED. // @@ -222,7 +218,7 @@ Handle process_handle(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id)); if (!process_handle) - return std::wstring(); + return false; std::wstring buffer(MAX_PATH, L'\0'); DWORD buf_size = buffer.length(); @@ -230,14 +226,15 @@ // Note that this function requires Windows Vista or above. You may use // GetProcessImageFileName or GetModuleFileNameEx on earlier versions. if (!::QueryFullProcessImageNameW(process_handle.get(), 0, &buffer.front(), &buf_size)) - return std::wstring(); + return false; buffer.resize(buf_size); - return ToUtf8String(buffer); + path = ToUtf8String(buffer); + return true; } static std::string GetFilenameFromPath(const std::string& path) { - const auto pos = path.find_last_of(L"/\\"); + const auto pos = path.find_last_of("/\\"); return pos != std::wstring::npos ? path.substr(pos + 1) : path; } @@ -270,11 +267,10 @@ /* extern functions */ bool GetProcessName(pid_t pid, std::string& name) { - std::string path = GetProcessPath(pid); - if (path.empty() || !VerifyProcessPath(path)) + if (!GetProcessPath(pid, name) || !VerifyProcessPath(name)) return false; - name = GetFilenameFromPath(path); + name = GetFilenameFromPath(name); if (!VerifyProcessFilename(name)) return false; @@ -297,7 +293,7 @@ if (!GetProcessName(pe32.th32ProcessID, name)) continue; - if (!process_proc({.platform = ExecutablePlatform::Win32, .pid = pe32.th32ProcessID, .comm = name})) + if (!process_proc({.pid = pe32.th32ProcessID, .platform = ExecutablePlatform::Win32, .comm = name})) return false; } while (::Process32Next(process_snap.get(), &pe32));
--- a/dep/animone/src/win/quartz.cc Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/src/win/quartz.cc Thu Jun 20 03:03:05 2024 -0400 @@ -272,7 +272,7 @@ Window win; win.platform = WindowPlatform::Quartz; - CFDictionaryGetValue(window, CFSTR("kCGWindowNumber"), win.id); + CFDictionaryGetValue(window, CFSTR("kCGWindowNumber"), win.id.quartz); GetProcessBundleIdentifier(proc.pid, win.class_name); GetWindowTitle(win.id, proc.pid, win.text);
--- a/dep/animone/src/win/win32.cc Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/src/win/win32.cc Thu Jun 20 03:03:05 2024 -0400 @@ -63,8 +63,8 @@ return true; } -static bool VerifyClassName(const std::wstring& name) { - static const std::set<std::wstring> invalid_names = { +static bool VerifyClassName(const std::string& name) { + static const std::set<std::string> invalid_names = { // System classes "#32770", // Dialog box "CabinetWClass", // Windows Explorer @@ -93,7 +93,7 @@ Window window; window.platform = WindowPlatform::Win32; - window.id = static_cast<unsigned int>(reinterpret_cast<ULONG_PTR>(hwnd)); + window.id.win32 = reinterpret_cast<std::uintptr_t>(hwnd); window.text = ToUtf8String(GetWindowText(hwnd)); window.class_name = ToUtf8String(GetWindowClassName(hwnd)); if (!VerifyClassName(window.class_name))
--- a/dep/animone/src/win/x11.cc Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/animone/src/win/x11.cc Thu Jun 20 03:03:05 2024 -0400 @@ -238,7 +238,7 @@ for (const auto& window_cookie : window_cookies) { Window win; - win.id = window_cookie.window; + win.id.x11 = window_cookie.window; { /* Class name */ XcbPtr<xcb_get_property_reply_t> reply(::xcb_get_property_reply(connection, window_cookie.class_name, NULL));
--- a/dep/anitomy/configure.ac Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/anitomy/configure.ac Thu Jun 20 03:03:05 2024 -0400 @@ -12,7 +12,7 @@ # Need this because libtool is weird AM_PROG_AR -LT_INIT +LT_INIT([win32-dll]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT \ No newline at end of file
--- a/dep/pugixml/configure.ac Wed Jun 19 23:21:19 2024 -0400 +++ b/dep/pugixml/configure.ac Thu Jun 20 03:03:05 2024 -0400 @@ -12,7 +12,7 @@ # Need this because libtool is weird AM_PROG_AR -LT_INIT +LT_INIT([win32-dll]) AC_CONFIG_FILES([Makefile]) AC_OUTPUT
--- a/rc/sys/win32/dark/dark.qss Wed Jun 19 23:21:19 2024 -0400 +++ b/rc/sys/win32/dark/dark.qss Thu Jun 20 03:03:05 2024 -0400 @@ -82,7 +82,7 @@ border-left: 0.04em solid #808080; border-right: 0.04em solid #808080; border-top: 0.04em solid #808080; - background-color: #353535; + background-color: #191919; min-width: 50px; padding-top: 0.23em; padding-bottom: 0.23em; @@ -95,7 +95,7 @@ QTabBar::tab:top:!selected { color: white; - background-color: #353535; + background-color: #191919; border: 0.04em solid #808080; border-radius: 0.09em; border-bottom-left-radius: 0em; @@ -104,13 +104,13 @@ } QTabBar::tab:top:next-selected { - border-right: 0.04em transparent #353535; + border-right: 0.04em transparent #191919; border-bottom-left-radius: 0em; border-bottom-right-radius: 0em; } QTabBar::tab:top:previous-selected { - border-left: 0.04em transparent #353535; + border-left: 0.04em transparent #191919; border-bottom-left-radius: 0em; border-bottom-right-radius: 0em; }