Skip to content

Commit

Permalink
[ncneofetch] use GetSystemInfo on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Nov 9, 2021
1 parent d43295c commit 378d402
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion doc/man/man3/notcurses_input.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions src/compat/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
83 changes: 58 additions & 25 deletions src/fetch/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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");
Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -276,6 +304,9 @@ linux_ncneofetch(fetched_info* fi){
fi->neologo = get_neofetch_art(distro);
}
free(distro);
#else
(void)fi;
#endif
return dinfo;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 2 additions & 7 deletions src/lib/fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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*
Expand Down
4 changes: 2 additions & 2 deletions src/lib/in.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/termdesc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 378d402

Please sign in to comment.