#define _XOPEN_SOURCE #include #include #include #include #include #include #include void valueChanged (Widget, XtPointer, XtPointer); void setBrightness (int); int getBrightness (); int getMaxBrightness (); int main (int argc, char *argv[]) { XtAppContext application; Widget window = XtVaAppInitialize ( &application, "Brightness", NULL, 0, &argc, argv, NULL, XmNtitle, "Brightness", NULL); int level = getBrightness(); int max = getMaxBrightness(); int percent = (float)(level) / (float)(max) * 100; Widget scale = XtVaCreateManagedWidget ( "Brightness", xmScaleWidgetClass, window, XmNmaximum, 100, XmNminimum, 1, XmNvalue, percent, NULL); XtAddCallback(scale, XmNvalueChangedCallback, valueChanged, NULL); XtVaSetValues(window, XmNmwmDecorations, MWM_DECOR_BORDER, NULL); XtVaSetValues(window, XmNmwmFunctions, MWM_FUNC_RESIZE, NULL); //XtVaSetValues(window, XtNheight, 400, NULL); //XtVaSetValues(window, XtNwidth, 400, NULL); XtRealizeWidget(window); XtAppMainLoop(application); } void valueChanged (Widget scale, XtPointer clientData, XtPointer callData) { (void)(scale); (void)(clientData); XmScaleCallbackStruct *event = (XmScaleCallbackStruct *)(callData); setBrightness(event->value); } void setBrightness (int level) { char command[32] = { 0 }; snprintf(command, 32, "brightnessctl s %d%% -q", level); system(command); } int getBrightness () { FILE *stream = popen("brightnessctl g", "r"); if (stream == NULL) { fprintf(stderr, "ERR could not get brightness\n"); return 1; } int result = 1; fscanf(stream, "%d", &result); pclose(stream); return result; } int getMaxBrightness () { FILE *stream = popen("brightnessctl m", "r"); if (stream == NULL) { fprintf(stderr, "ERR could not get brightness\n"); return 1; } int result = 1; fscanf(stream, "%d", &result); pclose(stream); return result; }