Created
August 28, 2017 14:04
-
-
Save anonymous/f7e4ba89c7b58443e3459eee4893611e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtk/gtk.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define borderSize 4 | |
#define fallbackCPUCount 4 | |
#define ignore(x) (void) x | |
struct CPUDisplay { | |
GtkWidget *box; | |
GtkWidget *toggle; | |
GtkWidget *usageBar; | |
}; | |
static gboolean deleteEventHandler (GtkWidget *widget, | |
GdkEvent *event, | |
gpointer data) { | |
/* ignored arguments */ | |
ignore(widget); | |
ignore(event); | |
ignore(data); | |
gtk_main_quit(); | |
return TRUE; | |
} | |
int main (int argc, char *argv[]) { | |
gtk_init(&argc, &argv); | |
int CPUCount = ((argc > 1) | |
? atoi(argv[1]) | |
: fallbackCPUCount); | |
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
gtk_container_set_border_width(GTK_CONTAINER (window), borderSize); | |
GtkWidget *hbox = gtk_hbox_new(FALSE, borderSize); | |
gtk_container_add(GTK_CONTAINER (window), hbox); | |
GtkWidget *alignment = gtk_alignment_new(0, 0, 0, 0); | |
gtk_box_pack_start(GTK_BOX (hbox), alignment, FALSE, FALSE, borderSize); | |
gtk_widget_show(alignment); | |
GtkWidget *image = gtk_image_new_from_file("placeholder.png"); | |
gtk_container_add(GTK_CONTAINER (alignment), image); | |
gtk_image_set_pixel_size(GTK_IMAGE (image), 1); | |
gtk_widget_show(image); | |
GtkWidget *vbox = gtk_vbox_new(TRUE, (borderSize * 2)); | |
gtk_container_add(GTK_CONTAINER (hbox), vbox); | |
struct CPUDisplay *CPUDisplays = malloc(sizeof (struct CPUDisplay) * CPUCount); | |
for (int i = 0; i < CPUCount; i += 1) { | |
char buf[15]; | |
sprintf(buf, "cpu%d", i); | |
struct CPUDisplay *current = &CPUDisplays[i]; | |
current->box = gtk_hbox_new(FALSE, borderSize); | |
gtk_container_add(GTK_CONTAINER (vbox), current->box); | |
current->toggle = gtk_toggle_button_new_with_label(buf); | |
current->usageBar = gtk_progress_bar_new(); | |
gtk_progress_bar_update(GTK_PROGRESS_BAR (current->usageBar), | |
(gdouble) (i + 1) / CPUCount); | |
gtk_box_pack_start(GTK_BOX (current->box), current->toggle, TRUE, FALSE, 0); | |
gtk_box_pack_start(GTK_BOX (current->box), current->usageBar, TRUE, TRUE, 0); | |
gtk_widget_show(current->toggle); | |
gtk_widget_show(current->usageBar); | |
gtk_widget_show(current->box); | |
} | |
/* show things */ | |
gtk_widget_show(vbox); | |
gtk_widget_show(hbox); | |
gtk_widget_show(window); | |
/* add event handlers */ | |
g_signal_connect(window, "delete-event", | |
G_CALLBACK (deleteEventHandler), NULL); | |
gtk_main(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.POSIX: | |
CFLAGS = -Wall -Wextra -g | |
CC = gcc | |
all: interface | |
interface: interface.c | |
$(CC) interface.c -o interface $(CFLAGS) $$(pkg-config --cflags --libs gtk+-2.0) | |
clean: | |
rm -f interface *~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment