From 214d8962e0cdfe36a36fc003c5eafbf6bd088aaa Mon Sep 17 00:00:00 2001 From: aristocratos Date: Mon, 23 Aug 2021 22:52:52 +0200 Subject: [PATCH] Moving stuff around --- Makefile | 40 +++++++++++++------ src/btop_draw.cpp | 5 ++- src/btop_input.cpp | 2 +- src/btop_platform.cpp | 36 ----------------- src/btop_tools.cpp | 2 +- .../btop_collect.cpp} | 1 + 6 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 src/btop_platform.cpp rename src/{btop_linux.hpp => linux/btop_collect.cpp} (99%) diff --git a/Makefile b/Makefile index 0b0db54..b0ee353 100644 --- a/Makefile +++ b/Makefile @@ -2,18 +2,18 @@ BANNER = \n \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m████████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗\n \033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗╚══\033[38;5;160m██\033[38;5;239m╔══╝\033[38;5;160m██\033[38;5;239m╔═══\033[38;5;160m██\033[38;5;239m╗\033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗\n \033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║\033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██████\033[38;5;238m╗\033[38;5;124m██████\033[38;5;238m╗\n \033[38;5;88m██\033[38;5;237m╔══\033[38;5;88m██\033[38;5;237m╗ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║\033[38;5;88m██\033[38;5;237m╔═══╝ ╚═\033[38;5;88m██\033[38;5;237m╔═╝╚═\033[38;5;88m██\033[38;5;237m╔═╝\n \033[38;5;52m██████\033[38;5;236m╔╝ \033[38;5;52m██\033[38;5;236m║ ╚\033[38;5;52m██████\033[38;5;236m╔╝\033[38;5;52m██\033[38;5;236m║ ╚═╝ ╚═╝\n \033[38;5;235m╚═════╝ ╚═╝ ╚═════╝ ╚═╝ \033[1;3;38;5;240mMakefile v1.0\033[0m -BTOP_VERSION = $(shell head -n100 src/btop.cpp 2>/dev/null | grep "Version =" | cut -f2 -d"\"" || echo " unknown") -TIMESTAMP = $(shell date +%s 2>/dev/null || echo "0") +BTOP_VERSION := $(shell head -n100 src/btop.cpp 2>/dev/null | grep "Version =" | cut -f2 -d"\"" || echo " unknown") +TIMESTAMP := $(shell date +%s 2>/dev/null || echo "0") PREFIX ?= /usr/local #? Compiler and Linker CXX ?= g++ -CXX_VERSION = $(shell $(CXX) -dumpfullversion -dumpversion || echo 0) +CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion || echo 0) #? Try to make sure we are using GCC/G++ version 11 or later if not instructed to use g++-10 ifneq ($(CXX),g++-10) - V_MAJOR = $(shell echo $(CXX_VERSION) | cut -f1 -d"." || echo 0) + V_MAJOR = $(shell echo $(CXX_VERSION) | cut -f1 -d".") ifneq ($(shell test $(V_MAJOR) -ge 11; echo $$?),0) ifeq ($(shell command -v g++-11 >/dev/null; echo $$?),0) override CXX = g++-11 @@ -22,14 +22,16 @@ ifneq ($(CXX),g++-10) endif #? Only enable fcf-protection if on x86_64 -ARCH = $(shell uname -p || echo unknown) +ARCH := $(shell uname -p || echo unknown) +ifeq ($(ARCH),unknown) + ARCH := $(shell uname -m || echo unknown) +endif ifeq ($(ARCH),x86_64) ADDFLAGS = -fcf-protection endif -ifeq ($(ARCH),unknown) - ARCH = $(shell uname -m || echo unknown) -endif -PLATFORM = $(shell uname -s || echo unknown) + +#? Manually set this to (Linux|FreeBSD|Darwin) if not building for host platform +PLATFORM ?= $(shell uname -s || echo unknown) #? Use all CPU cores (will only be set if using Make 4.3+) MAKEFLAGS := --jobs=$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) @@ -54,8 +56,19 @@ INC := -I$(INCDIR) -I$(SRCDIR) SU_USER := root SU_GROUP := root -SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) -OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT))) +SOURCES := $(shell find $(SRCDIR) -maxdepth 1 -type f -name *.$(SRCEXT)) + +ifeq ($(PLATFORM),Linux) + SOURCES += $(shell find $(SRCDIR)/linux -type f -name *.$(SRCEXT)) +endif +ifeq ($(PLATFORM),FreeBSD) + SOURCES += $(shell find $(SRCDIR)/freebsd -type f -name *.$(SRCEXT)) +endif +ifeq ($(PLATFORM),Darwin) + SOURCES += $(shell find $(SRCDIR)/osx -type f -name *.$(SRCEXT)) +endif + +OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT))) #? Default Make all: msg directories btop @@ -67,7 +80,7 @@ msg: @printf "\033[1;97mWARNFLAGS : \033[0m$(WARNFLAGS)\n" @printf "\033[1;97mOPTFLAGS : \033[0m$(OPTFLAGS)\n" @printf "\033[1;97mLDCXXFLAGS : \033[0m$(LDCXXFLAGS)\n" - @printf "\n\033[1;92mBuilding btop++ v$(BTOP_VERSION) on $(PLATFORM) ($(ARCH))\033[0m\n" + @printf "\n\033[1;92mBuilding \033[1;91mbtop++ \033[1;93mv$(BTOP_VERSION) \033[0;37mfor \033[1;97m$(PLATFORM) \033[1;96m($(ARCH))\033[0m\n" help: @printf "\033[1;97mbtop++ makefile\033[0m\n" @@ -84,6 +97,9 @@ help: directories: @mkdir -p $(TARGETDIR) @mkdir -p $(BUILDDIR) + @mkdir -p $(BUILDDIR)/linux + @mkdir -p $(BUILDDIR)/freebsd + @mkdir -p $(BUILDDIR)/osx #? Clean only Objects clean: diff --git a/src/btop_draw.cpp b/src/btop_draw.cpp index 3ab01bb..297b00a 100644 --- a/src/btop_draw.cpp +++ b/src/btop_draw.cpp @@ -616,7 +616,7 @@ namespace Mem { + 'i' + Theme::c("title") + 'o' + Fx::ub + Theme::c("mem_box") + Symbols::title_right; Input::mouse_mappings["i"] = {y, x + width - 5, 1, 2}; } - + } //? Mem and swap @@ -810,7 +810,7 @@ namespace Net { } //? IP or device address - if (not ip_addr.empty() and width - i_size - 35 - ip_addr.size() > 0) { + if (not ip_addr.empty() and cmp_greater(width - i_size - 36, ip_addr.size())) { out += Mv::to(y, x + 8) + title_left + Theme::c("title") + Fx::b + ip_addr + title_right; } @@ -1418,6 +1418,7 @@ namespace Draw { box = createBox(x, y, width, height, Theme::c("mem_box"), true, "mem", "", 2); box += Mv::to(y, (show_disks ? divider + 2 : x + width - 9)) + Theme::c("mem_box") + Symbols::title_left + (show_disks ? Fx::b : "") + Theme::c("hi_fg") + 'd' + Theme::c("title") + "isks" + Fx::ub + Theme::c("mem_box") + Symbols::title_right; + Input::mouse_mappings["d"] = {y, (show_disks ? divider + 3 : x + width - 8), 1, 5}; if (show_disks) { box += Mv::to(y, divider) + Symbols::div_up + Mv::to(y + height - 1, divider) + Symbols::div_down + Theme::c("div_line"); for (auto i : iota(1, height - 1)) diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 33f6d35..932f561 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -391,7 +391,7 @@ namespace Input { if (key == "i") { Config::flip("io_mode"); } - if (key == "d") { + else if (key == "d") { Config::flip("show_disks"); no_update = false; Draw::calcSizes(); diff --git a/src/btop_platform.cpp b/src/btop_platform.cpp deleted file mode 100644 index f7e256d..0000000 --- a/src/btop_platform.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2021 Aristocratos (jakob@qvantnet.com) - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -indent = tab -tab-size = 4 -*/ - - -#if defined(__linux__) - #include -#elif defined(__unix__) or not defined(__APPLE__) and defined(__MACH__) - #include - #if defined(__FreeBSD__) - #error FreeBSD support not yet implemented! - //#include - #endif -#elif defined(__APPLE__) and defined(__MACH__) - #include - #if TARGET_OS_MAC == 1 - #error OSX support not yet implemented! - //#include - #endif -#else - #error Platform not supported! -#endif \ No newline at end of file diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index a42d96d..d299d80 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -353,7 +353,7 @@ namespace Tools { string username() { auto user = getenv("LOGNAME"); - if (user == NULL or strcmp(user, "")) user = getenv("USER"); + if (user == NULL or strlen(user) == 0) user = getenv("USER"); return (user != NULL ? user : ""); } diff --git a/src/btop_linux.hpp b/src/linux/btop_collect.cpp similarity index 99% rename from src/btop_linux.hpp rename to src/linux/btop_collect.cpp index ea3535f..fc1963c 100644 --- a/src/btop_linux.hpp +++ b/src/linux/btop_collect.cpp @@ -1004,6 +1004,7 @@ namespace Proc { cur_depth = 0; } } + else if (cur_proc.filtered) cur_proc.filtered = false; //? Set tree index position for process if not filtered out or currently in a collapsed sub-tree if (not collapsed and not filtering) {