Skip to content

Commit

Permalink
Code optimization, fix tooltips, fix threads, better behavior on
Browse files Browse the repository at this point in the history
realtime configuration changes
  • Loading branch information
ItzSelenux authored and ItzSelenux committed Sep 13, 2024
1 parent d1169ae commit b240f61
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 365 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Continous CI

permissions:
contents: write

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up variables
id: date
run: |
echo "GH_RELEASE_FILE=gxcapindicator-$(cat VERSION)-$(ldd --version | awk '/ldd/{print "-gnu-" $NF}')" >> $GITHUB_ENV
echo "GH_RELEASE_VERSION=$(cat VERSION)" >> $GITHUB_ENV
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
libgtk-3-dev \
libayatana-appindicator3-dev \
pkg-config \
clang
- name: Build with GCC
run: |
make CC=gcc
strip gxcapindicator
mv gxcapindicator ${{ env.GH_RELEASE_FILE }}
- name: Build with Clang
run: |
make CC=clang
continue-on-error: true

- name: Build with -Werror
run: |
make CFLAGS=-Werror
continue-on-error: true

- name: Release
uses: softprops/action-gh-release@v2
with:
name: Release ci-${{ env.GH_RELEASE_VERSION}}
body: ${{ github.event.head_commit.message }}
tag_name: ${{ env.GH_RELEASE_VERSION }}
files: |
${{ env.GH_RELEASE_FILE }}
32 changes: 15 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC = gcc
CFLAGS = `pkg-config --cflags gtk+-3.0 ayatana-appindicator3-0.1` -Wall -lpthread -lX11
LIBS = `pkg-config --libs gtk+-3.0 ayatana-appindicator3-0.1` -Wall -lpthread -lX11
CC = cc
CFLAGS = `pkg-config --cflags gtk+-3.0 ayatana-appindicator3-0.1` -Wall
LIBS = `pkg-config --libs gtk+-3.0 ayatana-appindicator3-0.1` -lpthread -lX11

SRC = gxcapindicator.c
OBJ = $(SRC:.c=.o)
Expand All @@ -21,19 +21,17 @@ clean:
rm -f $(OBJ) $(EXE) debug

install: $(EXE)
install -Dm755 $(EXE) /usr/bin/$(EXE)
install -Dm755 gxcapindicator.desktop /usr/share/applications/gxcapindicator.desktop
install -Dm644 gxcapindicator.conf /etc/gxcapindicator.conf
install -Dm644 icons/keyboard-caps-disabled.svg /usr/share/icons/hicolor/32x32/devices/keyboard-caps-disabled.svg
install -Dm644 icons/keyboard-caps-enabled.svg /usr/share/icons/hicolor/32x32/devices/keyboard-caps-enabled.svg
install -Dm644 icons/keyboard-num-disabled.svg /usr/share/icons/hicolor/32x32/devices/keyboard-num-disabled.svg
install -Dm644 icons/keyboard-num-enabled.svg /usr/share/icons/hicolor/32x32/devices/keyboard-num-enabled.svg
install -Dm755 $(EXE) /usr/local/bin/$(EXE)
install -Dm755 gxcapindicator.desktop /usr/local/share/applications/gxcapindicator.desktop
install -Dm644 icons/keyboard-caps-disabled.svg /usr/local/share/icons/hicolor/32x32/devices/keyboard-caps-disabled.svg
install -Dm644 icons/keyboard-caps-enabled.svg /usr/local/share/icons/hicolor/32x32/devices/keyboard-caps-enabled.svg
install -Dm644 icons/keyboard-num-disabled.svg /usr/local/share/icons/hicolor/32x32/devices/keyboard-num-disabled.svg
install -Dm644 icons/keyboard-num-enabled.svg /usr/local/share/icons/hicolor/32x32/devices/keyboard-num-enabled.svg

uninstall:
rm -f /usr/bin/$(EXE)
rm -f /usr/share/applications/gxcapindicator.desktop
rm -f /etc/gxcapindicator.conf
rm -f /usr/share/icons/hicolor/32x32/devices/keyboard-caps-disabled.svg
rm -f /usr/share/icons/hicolor/32x32/devices/keyboard-caps-enabled.svg
rm -f /usr/share/icons/hicolor/32x32/devices/keyboard-num-disabled.svg
rm -f /usr/share/icons/hicolor/32x32/devices/keyboard-num-enabled.svg
rm -f /usr/local/bin/$(EXE)
rm -f /usr/local/share/applications/gxcapindicator.desktop
rm -f /usr/local/share/icons/hicolor/32x32/devices/keyboard-caps-disabled.svg
rm -f /usr/local/share/icons/hicolor/32x32/devices/keyboard-caps-enabled.svg
rm -f /usr/local/share/icons/hicolor/32x32/devices/keyboard-num-disabled.svg
rm -f /usr/local/share/icons/hicolor/32x32/devices/keyboard-num-enabled.svg
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# gxcapindicator

<img src="https://raw.githubusercontent.com/ItzSelenux/ItzSelenux.github.io/main/res/projects/gxcapindicator.svg" alt="Description of Image" width="111px" />


Simple Cap/Num lock key indicator for x11 tray

## Features:
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1
56 changes: 56 additions & 0 deletions cfgmgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
void cancelconfig()
{
gtk_widget_destroy(dialog);
}

void on_preferences(GtkWidget *button, gpointer data)
{
dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(dialog), "GXCapIndicator Settings");

theme = gtk_icon_theme_get_default();
info = gtk_icon_theme_lookup_icon(theme, "keyboard-caps-enabled", 48, 0);
if (info != NULL)
{
icon = gtk_icon_info_load_icon(info, NULL);
gtk_window_set_icon(GTK_WINDOW(dialog), icon);
g_object_unref(icon);
g_object_unref(info);
}

gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);

grid = gtk_grid_new();
gtk_container_add(GTK_CONTAINER(dialog), grid);
gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE);
gtk_grid_set_row_homogeneous(GTK_GRID(grid), TRUE);

gshowcap = gtk_check_button_new();
gshownum = gtk_check_button_new();
gupdrate = gtk_entry_new();

btn_cancel = gtk_button_new_with_label("cancel");
btn_savesettings = gtk_button_new_with_label("save");

gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Show Caps Lock:"), 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), gshowcap, 1, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Show Num Lock:"), 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), gshownum, 1, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), gtk_label_new("Update rate (seconds):"), 0, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid), gupdrate, 1, 2, 1, 1);
gtk_grid_attach(GTK_GRID(grid), btn_cancel, 0, 6, 1, 1);
gtk_grid_attach(GTK_GRID(grid), btn_savesettings, 1, 6, 1, 1);

gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gshowcap), !!showcap);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gshownum), !!shownum);

char buffer[32];
snprintf(buffer, sizeof(buffer), "%d", updrate);
gtk_entry_set_text(GTK_ENTRY(gupdrate), buffer);

g_signal_connect(btn_cancel, "clicked", G_CALLBACK(cancelconfig), NULL);
g_signal_connect(btn_savesettings, "clicked", G_CALLBACK(saveconfig), dialog);
gtk_widget_show_all(dialog);
gtk_main();
}
78 changes: 2 additions & 76 deletions gxcapindicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,6 @@
int main(int argc, char *argv[])
{
readconf();

printf("num=%d cap=%d", shownum, showcap);
pthread_t thread_id;
if (pthread_create(&thread_id, NULL, check_caps_lock, NULL) != 0)
{
fprintf(stderr, "Error creating thread\n");
return 1;
}

if (pthread_create(&thread_id, NULL, check_num_lock, NULL) != 0)
{
fprintf(stderr, "Error creating thread\n");
return 1;
}

gtk_init(&argc, &argv);

// Cap Tray Icon
indicator = app_indicator_new("gxcapindicator-capslock", "GXCapIndicator", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
if (showcap)
{
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
}
app_indicator_set_icon_full(indicator, "image-loading-symbolic", "Caps Lock");

traymenu = gtk_menu_new();
traymenu_item1 = gtk_menu_item_new_with_label("Toggle Caps Lock");
traymenu_item2 = gtk_menu_item_new_with_label("Settings");
traymenu_item3 = gtk_menu_item_new_with_label("About");
traymenu_item4 = gtk_menu_item_new_with_label("Quit");
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu), traymenu_item1);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu), traymenu_item2);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu), traymenu_item3);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu), traymenu_item4);
gtk_widget_show_all(traymenu);
app_indicator_set_menu(indicator, GTK_MENU(traymenu));


// Num Tray Icon
indicator2 = app_indicator_new("gxcapindicator-numlock","GXCapIndicator",APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
if (shownum)
{
app_indicator_set_status(indicator2, APP_INDICATOR_STATUS_ACTIVE);
}
app_indicator_set_label(indicator2, "Indicator 2", NULL);
app_indicator_set_icon_full(indicator2, "image-loading-symbolic", "Num Lock");

traymenu2 = gtk_menu_new();
traymenu_item11 = gtk_menu_item_new_with_label("Toggle Num Lock");
traymenu_item12 = gtk_menu_item_new_with_label("Settings");
traymenu_item13 = gtk_menu_item_new_with_label("About");
traymenu_item14 = gtk_menu_item_new_with_label("Quit");
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu2), traymenu_item11);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu2), traymenu_item12);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu2), traymenu_item13);
gtk_menu_shell_append(GTK_MENU_SHELL(traymenu2), traymenu_item14);
gtk_widget_show_all(traymenu2);
app_indicator_set_menu(indicator2, GTK_MENU(traymenu2));


g_signal_connect(G_OBJECT(traymenu_item1), "activate", G_CALLBACK(toggle_cap), NULL);
g_signal_connect(G_OBJECT(traymenu_item2), "activate", G_CALLBACK(on_preferences), NULL);
g_signal_connect(G_OBJECT(traymenu_item3), "activate", G_CALLBACK(on_about), NULL);
g_signal_connect(G_OBJECT(traymenu_item4), "activate", G_CALLBACK(quit_app), NULL);

g_signal_connect(G_OBJECT(traymenu_item11), "activate", G_CALLBACK(toggle_num), NULL);
g_signal_connect(G_OBJECT(traymenu_item12), "activate", G_CALLBACK(on_preferences), NULL);
g_signal_connect(G_OBJECT(traymenu_item13), "activate", G_CALLBACK(on_about), NULL);
g_signal_connect(G_OBJECT(traymenu_item14), "activate", G_CALLBACK(quit_app), NULL);

gtk_main();

pthread_cancel(thread_id);
pthread_join(thread_id, NULL);

return 0;
}
create_window();
}
Loading

0 comments on commit b240f61

Please sign in to comment.