moved code here. still needs to update gh
This commit is contained in:
20
brightness_menu/Makefile
Normal file
20
brightness_menu/Makefile
Normal file
@@ -0,0 +1,20 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra -Iinclude `pkg-config --cflags gtk+-3.0`
|
||||
LDFLAGS = -lncurses -lX11 -lXrandr `pkg-config --libs gtk+-3.0`
|
||||
|
||||
SRC = $(wildcard src/*.c)
|
||||
OBJ = $(patsubst src/%.c, build/%.o, $(SRC))
|
||||
TARGET = build/screen_control
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) -o $(TARGET) $(OBJ) $(LDFLAGS)
|
||||
|
||||
build/%.o: src/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f build/*.o $(TARGET)
|
||||
|
||||
.PHONY: all clean
|
||||
0
brightness_menu/README.md
Normal file
0
brightness_menu/README.md
Normal file
BIN
brightness_menu/build/brightness.o
Normal file
BIN
brightness_menu/build/brightness.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/color_temperature.o
Normal file
BIN
brightness_menu/build/color_temperature.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/display.o
Normal file
BIN
brightness_menu/build/display.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/main.o
Normal file
BIN
brightness_menu/build/main.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/refresh_rate.o
Normal file
BIN
brightness_menu/build/refresh_rate.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/resolution.o
Normal file
BIN
brightness_menu/build/resolution.o
Normal file
Binary file not shown.
BIN
brightness_menu/build/screen_control
Executable file
BIN
brightness_menu/build/screen_control
Executable file
Binary file not shown.
6
brightness_menu/include/brightness.h
Normal file
6
brightness_menu/include/brightness.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef BRIGHTNESS_H
|
||||
#define BRIGHTNESS_H
|
||||
|
||||
void adjust_brightness();
|
||||
|
||||
#endif // BRIGHTNESS_H
|
||||
6
brightness_menu/include/color_temperature.h
Normal file
6
brightness_menu/include/color_temperature.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef COLOR_TEMPERATURE_H
|
||||
#define COLOR_TEMPERATURE_H
|
||||
|
||||
void adjust_color_temperature();
|
||||
|
||||
#endif // COLOR_TEMPERATURE_H
|
||||
7
brightness_menu/include/display.h
Normal file
7
brightness_menu/include/display.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
void display_main_screen();
|
||||
void handle_option(int option);
|
||||
|
||||
#endif // DISPLAY_H
|
||||
6
brightness_menu/include/refresh_rate.h
Normal file
6
brightness_menu/include/refresh_rate.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef REFRESH_RATE_H
|
||||
#define REFRESH_RATE_H
|
||||
|
||||
void adjust_refresh_rate();
|
||||
|
||||
#endif // REFRESH_RATE_H
|
||||
6
brightness_menu/include/resolution.h
Normal file
6
brightness_menu/include/resolution.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef RESOLUTION_H
|
||||
#define RESOLUTION_H
|
||||
|
||||
void adjust_resolution();
|
||||
|
||||
#endif // RESOLUTION_H
|
||||
53
brightness_menu/src/brightness.c
Normal file
53
brightness_menu/src/brightness.c
Normal 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();
|
||||
}
|
||||
BIN
brightness_menu/src/brightness.o
Normal file
BIN
brightness_menu/src/brightness.o
Normal file
Binary file not shown.
26
brightness_menu/src/color_temperature.c
Normal file
26
brightness_menu/src/color_temperature.c
Normal 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();
|
||||
}
|
||||
49
brightness_menu/src/display.c
Normal file
49
brightness_menu/src/display.c
Normal 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();
|
||||
}
|
||||
|
||||
BIN
brightness_menu/src/display.o
Normal file
BIN
brightness_menu/src/display.o
Normal file
Binary file not shown.
60
brightness_menu/src/main.c
Normal file
60
brightness_menu/src/main.c
Normal 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
BIN
brightness_menu/src/main.o
Normal file
Binary file not shown.
76
brightness_menu/src/refresh_rate.c
Normal file
76
brightness_menu/src/refresh_rate.c
Normal 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();
|
||||
}
|
||||
66
brightness_menu/src/resolution.c
Normal file
66
brightness_menu/src/resolution.c
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user