From 378d4022ce2ac1d6c4ed836a73b56b96fd02a3b0 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 9 Nov 2021 00:01:21 -0500 Subject: [PATCH] [ncneofetch] use GetSystemInfo on Windows --- doc/man/man3/notcurses_input.3.md | 2 +- src/compat/compat.h | 2 - src/fetch/main.c | 83 +++++++++++++++++++++---------- src/lib/fd.c | 9 +--- src/lib/in.c | 4 +- src/lib/termdesc.c | 6 ++- 6 files changed, 67 insertions(+), 39 deletions(-) diff --git a/doc/man/man3/notcurses_input.3.md b/doc/man/man3/notcurses_input.3.md index ec8111432d..425a7b3ccd 100644 --- a/doc/man/man3/notcurses_input.3.md +++ b/doc/man/man3/notcurses_input.3.md @@ -197,7 +197,7 @@ issues are resolved. You can determine whether the protocol is in use by examining the output of **notcurses-info(1)**. If the **kbd** property is indicated, you're using the Kitty protocol. -Mouse events in the top and left margins will never be delivered to the +Mouse events in the left margins will never be delivered to the application (as is intended), but mouse events in the bottom and right margins sometimes can be if the event occurs prior to a window resize. diff --git a/src/compat/compat.h b/src/compat/compat.h index 81784f5803..0b194dae23 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -44,8 +44,6 @@ extern "C" { typedef struct siginfo_t { int aieeee; } siginfo_t; -// not declared in MSYS2 header files, but implemented...? -int faccessat(int dirfd, const char *pathname, int mode, int flags); #define sigset_t int #define nl_langinfo(x) "UTF-8" #define ppoll(w, x, y, z) WSAPoll((w), (x), (y)) diff --git a/src/fetch/main.c b/src/fetch/main.c index 8e04cd41c5..047ac0283c 100644 --- a/src/fetch/main.c +++ b/src/fetch/main.c @@ -65,29 +65,6 @@ fetch_env_vars(struct notcurses* nc, fetched_info* fi){ return 0; } -static distro_info distros[] = { - { - .name = "arch", - // from core/filesystem - .logofile = "/usr/share/pixmaps/archlinux.png", - }, { - .name = "artix", - // from system/filesystem - .logofile = "/usr/share/pixmaps/artixlinux-logo.png", - }, { - .name = "debian", - // from desktop-base package - .logofile = "/usr/share/desktop-base/debian-logos/logo-text-256.png", - }, { - .name = "fedora", - // from redhat-lsb-core package - .logofile = "/usr/share/pixmaps/fedora-logo.png", - }, { - .name = NULL, - .logofile = NULL, - }, -}; - static int fetch_bsd_cpuinfo(fetched_info* fi){ #if defined(__linux__) || defined(__gnu_hurd__) || defined(__MINGW64__) @@ -110,6 +87,32 @@ fetch_bsd_cpuinfo(fetched_info* fi){ return 0; } +static int +fetch_windows_cpuinfo(fetched_info* fi){ +#ifdef __MINGW64__ + LPSYSTEM_INFO info; + GetSystemInfo(info); + switch(info->wProcessorArchitecture){ + case PROCESSOR_ARCHITECTURE_AMD64: + fi->cpu_model = strdup("amd64"); break; + case PROCESSOR_ARCHITECTURE_ARM: + fi->cpu_model = strdup("ARM"); break; + case PROCESSOR_ARCHITECTURE_ARM64: + fi->cpu_model = strdup("AArch64"); break; + case PROCESSOR_ARCHITECTURE_IA64: + fi->cpu_model = strdup("Itanium"); break; + case PROCESSOR_ARCHITECTURE_INTEL: + fi->cpu_model = strdup("i386"); break; + default: + fi->cpu_model = strdup("Unknown processor"); break; + } + fi->core_count = info->dwNumberOfProcessors; +#else + (void)fi; +#endif + return 0; +} + static int fetch_cpu_info(fetched_info* fi){ FILE* cpuinfo = fopen("/proc/cpuinfo", "re"); @@ -197,6 +200,7 @@ fetch_x_props(fetched_info* fi){ return 0; } +#ifdef __linux__ // Given a filename, check for its existence in the directories specified by // https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html. // Returns NULL if no such file can be found. Return value is heap-allocated. @@ -217,10 +221,35 @@ get_xdg_logo(const char *spec){ strcat(p, spec); return p; } +#endif // FIXME deal more forgivingly with quotation marks static const distro_info* linux_ncneofetch(fetched_info* fi){ + const distro_info* dinfo = NULL; +#ifdef __linux__ + static const distro_info distros[] = { + { + .name = "arch", + // from core/filesystem + .logofile = "/usr/share/pixmaps/archlinux.png", + }, { + .name = "artix", + // from system/filesystem + .logofile = "/usr/share/pixmaps/artixlinux-logo.png", + }, { + .name = "debian", + // from desktop-base package + .logofile = "/usr/share/desktop-base/debian-logos/logo-text-256.png", + }, { + .name = "fedora", + // from redhat-lsb-core package + .logofile = "/usr/share/pixmaps/fedora-logo.png", + }, { + .name = NULL, + .logofile = NULL, + }, + }; FILE* osinfo = fopen("/etc/os-release", "re"); if(osinfo == NULL){ return NULL; @@ -266,7 +295,6 @@ linux_ncneofetch(fetched_info* fi){ if(distro == NULL){ return NULL; } - const distro_info* dinfo = NULL; for(dinfo = distros ; dinfo->name ; ++dinfo){ if(strcmp(dinfo->name, distro) == 0){ break; @@ -276,6 +304,9 @@ linux_ncneofetch(fetched_info* fi){ fi->neologo = get_neofetch_art(distro); } free(distro); +#else + (void)fi; +#endif return dinfo; } @@ -314,7 +345,7 @@ get_kernel(fetched_info* fi){ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osvi); char ver[20]; // sure why not - snprintf(ver, sizeof(ver), "%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); + snprintf(ver, sizeof(ver), "%lu.%lu", osvi.dwMajorVersion, osvi.dwMinorVersion); fi->kernver = strdup(ver); fi->kernel = strdup("Windows NT"); return NCNEO_WINDOWS; @@ -671,6 +702,8 @@ ncneofetch(struct notcurses* nc){ } if(kern == NCNEO_LINUX){ fetch_cpu_info(&fi); + }else if(kern == NCNEO_WINDOWS){ + fetch_windows_cpuinfo(&fi); }else{ fetch_bsd_cpuinfo(&fi); } diff --git a/src/lib/fd.c b/src/lib/fd.c index b70052b996..965c83679d 100644 --- a/src/lib/fd.c +++ b/src/lib/fd.c @@ -233,11 +233,11 @@ launch_pipe_process(int* pipefd, int* pidfd, unsigned usepath, } #endif +#ifndef __MINGW64__ // nuke the just-spawned process, and reap it. called before the subprocess // reader thread is launched (which otherwise reaps the subprocess). static int kill_and_wait_subproc(pid_t pid, int pidfd, int* status){ -#ifndef __MINGW64__ int ret = -1; // on linux, we try pidfd_send_signal, if the pidfd has been defined. // otherwise, we fall back to regular old kill(); @@ -258,12 +258,6 @@ kill_and_wait_subproc(pid_t pid, int pidfd, int* status){ return -1; } return 0; -#else - (void)pid; - (void)pidfd; - (void)status; - return -1; -#endif } // need a poll on both main fd and pidfd @@ -335,6 +329,7 @@ ncsubproc_launch(ncplane* n, ncsubproc* ret, const ncsubproc_options* opts, int } return ret->nfp; } +#endif // use of env implies usepath static ncsubproc* diff --git a/src/lib/in.c b/src/lib/in.c index 8ea6cc6f1c..12f3184b9b 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -502,11 +502,11 @@ mouse_click(inputctx* ictx, unsigned release, char follow){ logwarn("dropping click in margins %ld/%ld\n", y, x); return; } - if(x >= ictx->ti->dimx - (ictx->rmargin + ictx->lmargin)){ + if((unsigned)x >= ictx->ti->dimx - (ictx->rmargin + ictx->lmargin)){ logwarn("dropping click in margins %ld/%ld\n", y, x); return; } - if(y >= ictx->ti->dimy - (ictx->bmargin + ictx->tmargin)){ + if((unsigned)y >= ictx->ti->dimy - (ictx->bmargin + ictx->tmargin)){ logwarn("dropping click in margins %ld/%ld\n", y, x); return; } diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index e26474bd89..36c5c7aa9a 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -832,8 +832,10 @@ int interrogate_terminfo(tinfo* ti, FILE* out, unsigned utf8, logpanic("failed opening Windows ConPTY\n"); return -1; } - if(cursor_y && cursor_x){ - locate_cursor(ti, cursor_y, cursor_x); + unsigned ucy, ucx; + if(locate_cursor(ti, &ucy, &ucx) == 0){ + *cursor_y = ucy; + *cursor_x = ucx; } #elif defined(__linux__) ti->linux_fb_fd = -1;