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 fa62a66
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 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
38 changes: 36 additions & 2 deletions src/fetch/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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->DUMMYUNIONNAME.DUMMYSTRUCTNAME.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 +223,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 +244,13 @@ 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__
FILE* osinfo = fopen("/etc/os-release", "re");
if(osinfo == NULL){
return NULL;
Expand Down Expand Up @@ -266,7 +296,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 +305,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 +346,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 +703,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
2 changes: 2 additions & 0 deletions src/lib/fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ ncsubproc_waiter(void* vncsp){
return status;
}

#ifndef __MINGW64__
static ncfdplane*
ncsubproc_launch(ncplane* n, ncsubproc* ret, const ncsubproc_options* opts, int fd,
ncfdplane_callback cbfxn, ncfdplane_done_cb donecbfxn){
Expand All @@ -335,6 +336,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 fa62a66

Please sign in to comment.