changeset 97:18979b066284

animia/unix: fix a bunch of stuff that breaks OS X things
author Paper <mrpapersonic@gmail.com>
date Thu, 02 Nov 2023 13:14:15 -0400
parents bd68e4393e6f
children 582b2fca1561
files dep/animia/include/bsd.h dep/animia/include/os.h dep/animia/src/bsd.cpp dep/animia/src/main.cpp src/gui/pages/now_playing.cc src/gui/widgets/text.cc src/track/constants.cc
diffstat 7 files changed, 48 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/dep/animia/include/bsd.h	Wed Nov 01 15:16:49 2023 -0400
+++ b/dep/animia/include/bsd.h	Thu Nov 02 13:14:15 2023 -0400
@@ -7,8 +7,9 @@
 namespace Animia { namespace Unix {
 
 std::vector<int> get_all_pids();
-std::string get_process_name(int pid);
-std::vector<std::string> get_open_files(int pid);
+std::string get_process_name(const int pid);
+std::vector<std::string> get_open_files(const int pid);
+std::vector<std::string> filter_system_files(const std::vector<std::string>& in);
 std::unordered_map<int, std::vector<std::string>> get_all_open_files();
 
 } // namespace Unix
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dep/animia/include/os.h	Thu Nov 02 13:14:15 2023 -0400
@@ -0,0 +1,16 @@
+/* can this be moved to cmake? */
+#ifndef __animia__os_h
+#define __animia__os_h
+
+#ifdef __linux__
+#	define ON_LINUX
+#elif (defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
+#	if (defined(__APPLE__) && defined(__MACH__))
+#		define ON_OSX
+#	endif
+#	define ON_UNIX
+#elif defined(_WIN32)
+#	define ON_WINDOWS
+#endif
+
+#endif // __animia__os_h
\ No newline at end of file
--- a/dep/animia/src/bsd.cpp	Wed Nov 01 15:16:49 2023 -0400
+++ b/dep/animia/src/bsd.cpp	Thu Nov 02 13:14:15 2023 -0400
@@ -6,6 +6,8 @@
  * around the very C-like BSD system functions that are...
  * kind of unnatural to use in modern C++.
  **/
+#include "bsd.h"
+#include "os.h"
 #include <assert.h>
 #include <fcntl.h>
 #include <iostream>
@@ -56,7 +58,7 @@
 	return ret;
 }
 
-std::string get_process_name(int pid) {
+std::string get_process_name(const int pid) {
 	std::string ret;
 #ifdef __FreeBSD__
 	struct kinfo_proc* proc = kinfo_getproc(pid);
@@ -75,7 +77,7 @@
 	return ret;
 }
 
-std::vector<std::string> get_open_files(int pid) {
+std::vector<std::string> get_open_files(const int pid) {
 	/* note: this is OS X only right now. eventually, I'll find a way
 	   to do this in FreeBSD, OpenBSD and the like */
 	std::vector<std::string> ret;
@@ -103,7 +105,9 @@
 			if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
 				continue;
 
-			if (vnodeInfo.pfi.fi_openflags & O_WRONLY || vnodeInfo.pfi.fi_openflags & O_RDWR)
+			/* I *think* this is correct. For some reason, with VLC on macOS this thinks files are read/write,
+			   which is totally unnecessary and even harmful. */
+			if ((vnodeInfo.pfi.fi_status & O_ACCMODE) == O_WRONLY)
 				continue;
 
 			ret.push_back(vnodeInfo.pvip.vip_path);
@@ -112,6 +116,21 @@
 	return ret;
 }
 
+std::vector<std::string> filter_system_files(const std::vector<std::string>& in) {
+#ifdef ON_OSX
+	std::vector<std::string> ret;
+	for (const auto& str : in)
+		/* these are some places nobody would ever want to store media files. */
+		if (str.find("/Library") && str.find("/System") && str.find("/Applications") &&
+			str.find("/dev") && str.find("/private"))
+			ret.push_back(str);
+	return ret;
+#else
+	return in;
+#endif
+}
+
+
 std::unordered_map<int, std::vector<std::string>> get_all_open_files() {
 	std::unordered_map<int, std::vector<std::string>> map;
 	std::vector<int> pids = get_all_pids();
--- a/dep/animia/src/main.cpp	Wed Nov 01 15:16:49 2023 -0400
+++ b/dep/animia/src/main.cpp	Thu Nov 02 13:14:15 2023 -0400
@@ -1,16 +1,10 @@
 #include "bsd.h"
+#include "os.h"
 #include "linux.h"
 #include "win32.h"
 #include <string>
 #include <unordered_map>
 #include <vector>
-#ifdef __linux__
-#	define ON_LINUX
-#elif (defined(unix) || defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
-#	define ON_UNIX
-#elif defined(_WIN32)
-#	define ON_WINDOWS
-#endif
 
 namespace Animia {
 
@@ -53,6 +47,8 @@
 std::vector<std::string> filter_system_files(const std::vector<std::string>& source) {
 #ifdef ON_WINDOWS
 	return Windows::filter_system_files(source);
+#elif defined(ON_OSX)
+	return Unix::filter_system_files(source);
 #else
 	return source;
 #endif
--- a/src/gui/pages/now_playing.cc	Wed Nov 01 15:16:49 2023 -0400
+++ b/src/gui/pages/now_playing.cc	Thu Nov 02 13:14:15 2023 -0400
@@ -66,6 +66,7 @@
 
 	_info.reset(new AnimeInfoWidget(_main.get()));
 	_info->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
+	_info->layout()->setContentsMargins(0, 0, 0, 0);
 	main_layout->addWidget(_info.get());
 
 	/* "sidebar", includes... just the anime image :) */
--- a/src/gui/widgets/text.cc	Wed Nov 01 15:16:49 2023 -0400
+++ b/src/gui/widgets/text.cc	Thu Nov 02 13:14:15 2023 -0400
@@ -72,8 +72,8 @@
 }
 
 /* Equivalent to Paragraph(), but is only capable of showing one line. Only
-   exists because sometimes with SelectableSection it will let you go
-   out of bounds */
+   exists because with SelectableSection it will let you go
+   out of bounds and that looks really fugly for most things */
 Line::Line(QWidget* parent) : QLineEdit(parent) {
 	setFrame(false);
 	setReadOnly(true);
--- a/src/track/constants.cc	Wed Nov 01 15:16:49 2023 -0400
+++ b/src/track/constants.cc	Thu Nov 02 13:14:15 2023 -0400
@@ -12,7 +12,7 @@
 
 const std::vector<std::string> media_players = {
 #ifdef MACOSX
-    "VLC"
+    "VLC", "IINA", "QuickTime Player"
 #elif WIN32
     "vlc.exe", "mpc-hc.exe", "mpc-hc64.exe", "wmplayer.exe", "mpv.exe"
 #else // linux, unix, whatevs