moved code here. still needs to update gh

This commit is contained in:
klein panic
2025-02-24 15:18:44 -05:00
parent 9ca9f577a4
commit 2726432fe1
106 changed files with 4816 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#include <ncurses.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "brightness.h"
void adjust_brightness() {
FILE *brightness_file;
int brightness;
char path[] = "/sys/class/backlight/intel_backlight/brightness";
char max_brightness_path[] = "/sys/class/backlight/intel_backlight/max_brightness";
int max_brightness;
brightness_file = fopen(path, "r+");
if (brightness_file == NULL) {
mvprintw(4, 0, "Error: %s", strerror(errno));
refresh();
return;
}
FILE *max_brightness_file = fopen(max_brightness_path, "r");
if (max_brightness_file == NULL) {
mvprintw(4, 0, "Error: %s", strerror(errno));
fclose(brightness_file);
refresh();
return;
}
fscanf(max_brightness_file, "%d", &max_brightness);
fclose(max_brightness_file);
fscanf(brightness_file, "%d", &brightness);
mvprintw(4, 0, "Current Brightness: %d", brightness);
mvprintw(5, 0, "Max Brightness: %d", max_brightness);
mvprintw(6, 0, "Enter new brightness (0-%d): ", max_brightness);
refresh();
echo();
scanw("%d", &brightness);
noecho();
if (brightness < 0 || brightness > max_brightness) {
mvprintw(7, 0, "Invalid brightness value");
} else {
rewind(brightness_file);
fprintf(brightness_file, "%d", brightness);
fflush(brightness_file);
mvprintw(7, 0, "Brightness set to %d", brightness);
}
fclose(brightness_file);
refresh();
getch();
}

Binary file not shown.

View File

@@ -0,0 +1,26 @@
#include <ncurses.h>
#include <stdlib.h>
#include <stdio.h>
#include "color_temperature.h"
void adjust_color_temperature() {
mvprintw(4, 0, "Enter the desired color temperature (in Kelvin, e.g., 6500): ");
refresh();
echo();
int color_temp;
scanw("%d", &color_temp);
noecho();
char command[128];
snprintf(command, sizeof(command), "xcalib -co %d", color_temp);
int result = system(command);
if (result == -1) {
mvprintw(6, 0, "Failed to set color temperature");
} else {
mvprintw(6, 0, "Color temperature set to %dK", color_temp);
}
refresh();
getch();
}

View File

@@ -0,0 +1,49 @@
#include <ncurses.h>
#include <stdlib.h>
#include "display.h"
#include "brightness.h"
#include "resolution.h"
#include "refresh_rate.h"
#include "color_temperature.h"
void display_main_screen() {
int option;
mvprintw(0, 0, "Select an option:");
mvprintw(1, 0, "1. Screen Brightness");
mvprintw(2, 0, "2. Screen Resolution");
mvprintw(3, 0, "3. Refresh Rate");
mvprintw(4, 0, "4. Color Temperature");
mvprintw(5, 0, "5. Exit");
refresh();
option = getch() - '0';
handle_option(option);
}
void handle_option(int option) {
switch(option) {
case 1:
adjust_brightness();
break;
case 2:
adjust_resolution();
break;
case 3:
adjust_refresh_rate();
break;
case 4:
adjust_color_temperature();
break;
case 5:
endwin();
exit(0);
default:
mvprintw(6, 0, "Invalid option");
refresh();
getch();
break;
}
display_main_screen();
}

Binary file not shown.

View File

@@ -0,0 +1,60 @@
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include "display.h"
void run_cli();
void run_gui();
int main(int argc, char *argv[]) {
int opt;
int gui_mode = 0;
// Parse command-line arguments
while ((opt = getopt(argc, argv, "g")) != -1) {
switch (opt) {
case 'g':
gui_mode = 1;
break;
default:
fprintf(stderr, "Usage: %s [-g]\n", argv[0]);
exit(EXIT_FAILURE);
}
}
if (gui_mode) {
run_gui(argc, argv);
} else {
run_cli();
}
return 0;
}
void run_cli() {
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
display_main_screen();
endwin();
}
void run_gui(int argc, char *argv[]) {
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "Screen Control GUI");
gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
gtk_widget_show_all(window);
gtk_main();
}

BIN
brightness_menu/src/main.o Normal file

Binary file not shown.

View File

@@ -0,0 +1,76 @@
#include <ncurses.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <stdlib.h>
#include <stdio.h>
#include "refresh_rate.h"
void list_refresh_rates(XRRScreenResources *res, XRRCrtcInfo *crtc_info) {
mvprintw(5, 0, "Available Refresh Rates:");
int rate_count = 0;
for (int i = 0; i < res->nmode; i++) {
XRRModeInfo mode = res->modes[i];
for (int j = 0; j < crtc_info->noutput; j++) {
if (crtc_info->outputs[j] == mode.id) {
double refresh_rate = (double)mode.dotClock / (mode.hTotal * mode.vTotal);
mvprintw(6 + rate_count, 0, "%d: %.2f Hz", rate_count, refresh_rate);
rate_count++;
}
}
}
refresh();
}
void set_refresh_rate() {
// Placeholder for setting the refresh rate based on selected index
mvprintw(7, 0, "Setting refresh rate feature coming soon...");
refresh();
}
void adjust_refresh_rate() {
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
mvprintw(4, 0, "Unable to open X display");
refresh();
getch();
return;
}
Window root = DefaultRootWindow(dpy);
XRRScreenResources *res = XRRGetScreenResources(dpy, root);
if (res == NULL) {
mvprintw(4, 0, "Unable to get screen resources");
XCloseDisplay(dpy);
refresh();
getch();
return;
}
XRRCrtcInfo *crtc_info = XRRGetCrtcInfo(dpy, res, res->crtcs[0]);
if (crtc_info == NULL) {
mvprintw(4, 0, "Unable to get CRTC info");
XRRFreeScreenResources(res);
XCloseDisplay(dpy);
refresh();
getch();
return;
}
list_refresh_rates(res, crtc_info);
mvprintw(6 + res->nmode, 0, "Enter the index of the desired refresh rate: ");
refresh();
echo();
int rate_index;
scanw("%d", &rate_index);
noecho();
set_refresh_rate();
XRRFreeCrtcInfo(crtc_info);
XRRFreeScreenResources(res);
XCloseDisplay(dpy);
getch();
}

View File

@@ -0,0 +1,66 @@
#include <ncurses.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <stdlib.h>
#include <stdio.h>
#include "resolution.h"
void list_resolutions(XRRScreenResources *res) {
mvprintw(5, 0, "Available Resolutions:");
for (int i = 0; i < res->nmode; i++) {
XRRModeInfo mode = res->modes[i];
mvprintw(6 + i, 0, "%d: %dx%d", i, mode.width, mode.height);
}
refresh();
}
void set_resolution(Display *dpy, Window root, XRRScreenResources *res, int mode_index) {
if (mode_index < 0 || mode_index >= res->nmode) {
mvprintw(7 + res->nmode, 0, "Invalid mode index");
return;
}
XRRModeInfo mode = res->modes[mode_index];
XRRSetScreenSize(dpy, root, mode.width, mode.height, mode.width, mode.height);
XRRSetCrtcConfig(dpy, res, res->crtcs[0], CurrentTime, 0, 0, mode.id, RR_Rotate_0, NULL, 0);
mvprintw(7 + res->nmode, 0, "Resolution set to %dx%d", mode.width, mode.height);
refresh();
}
void adjust_resolution() {
Display *dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
mvprintw(4, 0, "Unable to open X display");
refresh();
getch();
return;
}
Window root = DefaultRootWindow(dpy);
XRRScreenResources *res = XRRGetScreenResources(dpy, root);
if (res == NULL) {
mvprintw(4, 0, "Unable to get screen resources");
XCloseDisplay(dpy);
refresh();
getch();
return;
}
list_resolutions(res);
mvprintw(6 + res->nmode, 0, "Enter the index of the desired resolution: ");
refresh();
echo();
int mode_index;
scanw("%d", &mode_index);
noecho();
set_resolution(dpy, root, res, mode_index);
XRRFreeScreenResources(res);
XCloseDisplay(dpy);
getch();
}