From e8e875f06334e070df13fc9aaedf2e2c456fb5cc Mon Sep 17 00:00:00 2001 From: Linux User <56880528+varmd@users.noreply.github.com> Date: Mon, 16 Sep 2024 00:04:02 +0400 Subject: [PATCH] * Update to Weston 14.0 * Add brightness control with ddccontrol * Add brightness control with brightnessctl * Add option to hide apps from /usr/share/applications * Add option to hide volume icon * Misc fixes and improvements --- PKGBUILD | 4 +- README.md | 37 +- source/source/build.sh | 2 +- .../icons/display-brightness-symbolic.svg | 4 + source/source/install.sh | 7 +- .../source/scripts/wayward-get-brightness-ctl | 22 + .../source/scripts/wayward-get-brightness-ddc | 19 + .../source/{ => scripts}/wayward-lsdesktopf | 0 source/source/shell-helper.c | 187 +++--- source/source/terminal.c | 31 +- source/source/wayward-shell.c | 575 +++++++++++++++--- source/source/window.c | 8 +- 12 files changed, 706 insertions(+), 190 deletions(-) create mode 100644 source/source/icons/display-brightness-symbolic.svg create mode 100644 source/source/scripts/wayward-get-brightness-ctl create mode 100644 source/source/scripts/wayward-get-brightness-ddc rename source/source/{ => scripts}/wayward-lsdesktopf (100%) diff --git a/PKGBUILD b/PKGBUILD index cdcb2f1..cff4c28 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ pkgname=wayward -pkgver=1.3.0 -pkgrel=2 +pkgver=1.4.0 +pkgrel=4 pkgdesc="wayward - fast desktop shell for wayland and weston" arch=('x86_64') url="https://github.com/varmd/wayward" diff --git a/README.md b/README.md index 43ab395..1dcb566 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,47 @@ For shutdown and reboot icons to work install sudo and add to /etc/sudoers ## Hiding apps in the app panel -Edit weston.ini and add hide-apps to the shell section. For example +Edit weston.ini and add hide-apps to the shell section. hide-apps=mpv,zathura,file-roller +## Hiding apps in the app panel + +To hide apps from /usr/share/applications edit weston.ini and add the following to the shell section. + + hide-all-apps=true + +## Brightness control with ddccontrol + +Since 1.4.0 it is possible to control monitor brightness with ddccontrol. +First install ddccontrol, and test to see if it is working with your monitor. +Then add the following to weston.ini, where example is the number from /dev/i2c-number +in the output of `ddccontrol -p`. Brightness can then be changed from the app panel. + + enable-brightness-ddc=true + ddc-i2c-number=example + +This feature is currently limited to desktops with a single monitor. + +## Brightness control with brightnessctl + +Since 1.4.0 it is possible to control laptop brightness with brightnessctl. +First install brightnessctl, and configure it to work with your laptop. +Then add the following to weston.ini, where example is the laptop backlight device name from `brightnessctl info` + + enable-brightness-ctl=true + brightnessctl-device=example ## Changing wallpaper Wallpapers are changed from weston.ini. See weston.ini documentation - https://www.mankier.com/5/weston.ini#Shell_Section-background-image +## Hiding sound control + +To hide the sound control edit weston.ini and add the following to the shell section. + + disable-sound-icons=true + ## Pincodes Since 1.2.5 it is now possible to set numeric, up to six digit, pincodes for the lock screen. @@ -86,6 +118,8 @@ To set a pincode run as root wayward-set-pincode, and then restart weston. For e ## Changelog +1.4.0 - Update to Weston 14.0. Add brightness control with ddcontrol or brightnessctl. + 1.3.0 - Update to Weston 13.0. Add red color option to the wayward-terminal. Add list of open apps without minimized apps. 1.2.5 - Add pincode to lock screen @@ -114,7 +148,6 @@ To set a pincode run as root wayward-set-pincode, and then restart weston. For e ## Known issues and limitations * If there are large number of applications in /usr/share/applications, app icons will overlap with system icons. This can be fixed by hiding apps in weston.ini. -* Misconfigured or broken audio such as AMD HDMI audio can cause crash on startup. As a workaround audio setup should be fixed. For example for AMD HDMI audio built-in soundcard can be used as a workaround - e.g by setting snd_hda_intel.index=1,0 if built in soundcard comes as second when running aplay -l * Multimonitor support - not tested after removal of GTK * Need to restart weston after a new app installation to see the new app icon in the panel. diff --git a/source/source/build.sh b/source/source/build.sh index a684219..b9f1fe6 100644 --- a/source/source/build.sh +++ b/source/source/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -WESTON_VER=13 +WESTON_VER=14 cd `dirname $0` diff --git a/source/source/icons/display-brightness-symbolic.svg b/source/source/icons/display-brightness-symbolic.svg new file mode 100644 index 0000000..e9b7707 --- /dev/null +++ b/source/source/icons/display-brightness-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/source/source/install.sh b/source/source/install.sh index cff4a8f..770cfd1 100644 --- a/source/source/install.sh +++ b/source/source/install.sh @@ -6,8 +6,10 @@ echo $1 echo $0 /usr/bin/install -Dm644 wayward "$1/usr/lib/weston/wayward" -/usr/bin/install -Dm644 wayward-lsdesktopf "$1/usr/lib/weston/wayward-lsdesktopf" -/usr/bin/install -Dm655 wayward-set-pincode "/usr/bin/wayward-set-pincode" +/usr/bin/install -Dm644 scripts/wayward-lsdesktopf "$1/usr/lib/weston/wayward-lsdesktopf" +/usr/bin/install -Dm644 scripts/wayward-get-brightness-ddc "$1/usr/lib/weston/wayward-get-brightness-ddc" +/usr/bin/install -Dm644 scripts/wayward-get-brightness-ctl "$1/usr/lib/weston/wayward-get-brightness-ctl" +/usr/bin/install -Dm655 wayward-set-pincode "$1/usr/bin/wayward-set-pincode" /usr/bin/install -Dm644 shell_helper.so "$1/usr/lib/weston/shell_helper.so" /usr/bin/install -Dm655 wayward-terminal "$1/usr/bin/wayward-terminal" /usr/bin/install -Dm655 wayward-pincode "$1/usr/lib/weston/wayward-pincode" @@ -25,5 +27,4 @@ rm -rf wayward-terminal mkdir -p $1/usr/share/wayward cp icons/* $1/usr/share/wayward/ -#make echo OOOK! diff --git a/source/source/scripts/wayward-get-brightness-ctl b/source/source/scripts/wayward-get-brightness-ctl new file mode 100644 index 0000000..6faee30 --- /dev/null +++ b/source/source/scripts/wayward-get-brightness-ctl @@ -0,0 +1,22 @@ +#!/bin/bash + +stringContains() { [ -z "${2##*$1*}" ]; } + +if [[ -z "$1" ]]; then + echo "no brightnessctl device" + exit; +fi + +OUT=`brightnessctl --device ${1} i 2>/dev/null` + +OUT=${OUT##*Current} + +OUT=${OUT##*\(} +OUT=${OUT%\%*} + +BRIGHTNESS=$OUT + +printf $BRIGHTNESS > $HOME/.cache/wayward-brightness + +exit; + diff --git a/source/source/scripts/wayward-get-brightness-ddc b/source/source/scripts/wayward-get-brightness-ddc new file mode 100644 index 0000000..24a5e1e --- /dev/null +++ b/source/source/scripts/wayward-get-brightness-ddc @@ -0,0 +1,19 @@ +#!/bin/bash + +stringContains() { [ -z "${2##*$1*}" ]; } + +if [[ -z "$1" ]]; then + echo "no i2c number" + exit; +fi + +OUT=`ddccontrol -r 0x10 dev:/dev/i2c-${1} 2>/dev/null | grep -i Control ` + +OUT=${OUT##*Control} + +OUT=${OUT#*/} +BRIGHTNESS=${OUT%/*} + +printf $BRIGHTNESS > $HOME/.cache/wayward-brightness +exit; + diff --git a/source/source/wayward-lsdesktopf b/source/source/scripts/wayward-lsdesktopf similarity index 100% rename from source/source/wayward-lsdesktopf rename to source/source/scripts/wayward-lsdesktopf diff --git a/source/source/shell-helper.c b/source/source/shell-helper.c index 9b309b2..c12881d 100644 --- a/source/source/shell-helper.c +++ b/source/source/shell-helper.c @@ -54,20 +54,6 @@ #define DEFAULT_SCALE 1.3 - -enum animation_type { - ANIMATION_NONE, - ANIMATION_ZOOM, - ANIMATION_FADE, - ANIMATION_DIM_LAYER, -}; - -enum fade_type { - FADE_IN, - FADE_OUT -}; - - enum exposay_target_state { EXPOSAY_TARGET_OVERVIEW, /* show all windows */ EXPOSAY_TARGET_CANCEL, /* return to normal, same focus */ @@ -154,11 +140,30 @@ struct exposay { struct exposay_output global_eoutput; struct exposay global_exposay = {0}; +static void exposay_set_state(struct desktop_shell *shell, + enum exposay_target_state state, + struct weston_seat *seat); +static void exposay_check_state(struct desktop_shell *shell, struct weston_seat *seat); +static void exposay_remove_mask(); + +//Copied from desktop-shell/shell.h + struct focus_surface { - struct weston_surface *surface; - struct weston_view *view; - struct weston_transform workspace_transform; + struct weston_curtain *curtain; +}; + +enum animation_type { + ANIMATION_NONE, + + ANIMATION_ZOOM, + ANIMATION_FADE, + ANIMATION_DIM_LAYER, +}; + +enum fade_type { + FADE_IN, + FADE_OUT }; struct workspace { @@ -172,18 +177,6 @@ struct workspace { struct weston_view_animation *focus_animation; }; - - - - - -static void exposay_set_state(struct desktop_shell *shell, - enum exposay_target_state state, - struct weston_seat *seat); -static void exposay_check_state(struct desktop_shell *shell, struct weston_seat *seat); -static void exposay_remove_mask(); - - struct shell_output { struct desktop_shell *shell; struct weston_output *output; @@ -201,7 +194,6 @@ struct shell_output { }; struct weston_desktop; - struct desktop_shell { struct weston_compositor *compositor; struct weston_desktop *desktop; @@ -215,6 +207,7 @@ struct desktop_shell { struct wl_listener show_input_panel_listener; struct wl_listener hide_input_panel_listener; struct wl_listener update_input_panel_listener; + struct wl_listener session_listener; struct weston_layer fullscreen_layer; struct weston_layer panel_layer; @@ -286,6 +279,7 @@ struct desktop_shell { struct timespec startup_time; }; + //struct weston_output * //get_default_output(struct weston_compositor *compositor); @@ -315,6 +309,16 @@ get_default_output(struct weston_compositor *compositor) struct weston_output, link); } + +static void +weston_layer_entry_remove(struct weston_layer_entry *entry) +{ + wl_list_remove(&entry->link); + wl_list_init(&entry->link); + entry->layer = NULL; +} + + struct weston_view * get_default_view(struct weston_surface *surface); @@ -337,15 +341,12 @@ shell_for_each_layer(struct desktop_shell *shell, shell_for_each_layer_func_t func, void *data); - struct wl_seat *panel_seat; -struct weston_seat *global_weston_seat; -struct weston_keyboard *panel_keyboard; - - +struct weston_seat *global_weston_seat = NULL; +struct weston_keyboard *panel_keyboard = NULL; struct desktop_shell *global_desktop_shell = NULL; -struct wl_array global_minimized_array; -struct wl_array global_exposay_views_array; +struct wl_array global_minimized_array = {0}; +struct wl_array global_exposay_views_array = {0}; struct shell_helper { struct weston_compositor *compositor; @@ -353,12 +354,10 @@ struct shell_helper { struct wl_listener destroy_listener; struct exposay_output eoutput; struct weston_layer *panel_layer; - struct weston_layer curtain_layer; struct weston_view *curtain_view; struct weston_view_animation *curtain_animation; uint32_t curtain_show; - struct wl_list slide_list; }; @@ -386,6 +385,11 @@ shell_helper_move_surface(struct wl_client *client, weston_log("Moving.. %d %d \n", x, y); + if (!weston_surface_is_mapped(surface)) { + weston_log("Surface unmapped \n", x, y); + return; + } + if(x == -13371) x = view->geometry.pos_offset.x; @@ -400,7 +404,6 @@ shell_helper_move_surface(struct wl_client *client, pos.c = weston_coord(x, y); } - weston_view_set_position(view, pos); weston_view_update_transform(view); weston_compositor_schedule_repaint(helper->compositor); @@ -416,7 +419,9 @@ configure_surface(struct weston_surface *es, struct weston_coord_surface new_ori if (wl_list_empty(&new_view->layer_link.link)) { /* be sure to append to the list, not insert */ - weston_layer_entry_insert(&existing_view->layer_link, &new_view->layer_link); +// weston_layer_entry_insert(&existing_view->layer_link, &new_view->layer_link); + + weston_view_move_to_layer(new_view, &existing_view->layer_link); weston_compositor_schedule_repaint(es->compositor); } } @@ -514,18 +519,24 @@ configure_panel(struct weston_surface *es, struct weston_coord_surface new_origi struct weston_coord_global pos; if (!weston_surface_is_mapped(es)) { - weston_log("Moving panel configure .. \n"); + weston_log("Moving panel configure .. \n", es->height); weston_surface_map(es); + + weston_log("Mapping panel configure 333 .. \n", es->height); assert(wl_list_empty(&es->views)); view = weston_view_create(es); assert(view); + weston_log("Moving panel configure 444 %d .. \n", es->height); + initial = 0; } - weston_view_move_to_layer(view, - &shell->panel_layer.view_list); + if (wl_list_empty(&view->layer_link.link)) { + weston_view_move_to_layer(view, &shell->panel_layer.view_list); + } if(!initial) { initial = 1; + weston_log("Moving panel configure - initial .. \n"); panel_move_initial(view, 0, output->height - es->height); } @@ -562,8 +573,7 @@ shell_helper_set_panel(struct wl_client *client, view_list.link); */ - /* set new configure functions that only ensure the surface is in the - * correct layer. */ + // set new configure functions surface->committed = configure_panel; //surface->committed_private = helper; } @@ -866,11 +876,6 @@ void fullscreen_binding(struct weston_keyboard *keyboard, const struct timespec printf(" /width %f \n", (float)((float)view->output->width/(float)view->surface->width)); printf(" /height %f \n", (float)((float)view->output->height / (float)view->surface->height)); - //if (!get_shell_surface(view->surface)) - // continue; - //if (view->output != output) - // continue; - esurface = malloc(sizeof(*esurface)); esurface->shell = shell; esurface->view = view; @@ -897,16 +902,12 @@ void fullscreen_binding(struct weston_keyboard *keyboard, const struct timespec return; - - //TODO figure out why below is not working??? wl_list_for_each(view, &workspace->layer.view_list.link, layer_link.link) { - wl_list_init(&transform.link); - weston_matrix_init(&transform.matrix); - wl_list_insert(&view->geometry.transformation_list, &transform.link); - - //wl_list_remove(&transform.link); + wl_list_init(&transform.link); + weston_matrix_init(&transform.matrix); + wl_list_insert(&view->geometry.transformation_list, &transform.link); //weston_matrix_scale(&transform.matrix, surface->output->width / surface->width, surface->output->height / surface->height, 1); //weston_matrix_scale(matrix, 0.5, 0.5, 1.0); @@ -982,12 +983,9 @@ shell_helper_bind_key_panel(struct wl_client *client, weston_compositor_add_key_binding(helper->compositor, KEY_MUTE, 0, mute_binding, shell); weston_compositor_add_key_binding(helper->compositor, KEY_VOLUMEDOWN , 0, volumedown_binding, shell); weston_compositor_add_key_binding(helper->compositor, KEY_VOLUMEUP , 0, volumeup_binding, shell); - weston_compositor_add_key_binding(helper->compositor, KEY_BRIGHTNESSUP, 0, brightnessup_binding, shell); weston_compositor_add_key_binding(helper->compositor, KEY_BRIGHTNESSDOWN, 0, brightnessdown_binding, shell); - - - +////// weston_compositor_add_key_binding(helper->compositor, KEY_S , MODIFIER_SUPER | MODIFIER_CTRL | MODIFIER_ALT, shutdown_binding, shell); weston_compositor_add_key_binding(helper->compositor, KEY_R , MODIFIER_SUPER | MODIFIER_CTRL | MODIFIER_ALT, restart_binding, shell); weston_compositor_add_key_binding(helper->compositor, KEY_T , MODIFIER_SUPER | MODIFIER_SHIFT, terminal_binding, shell); @@ -1204,8 +1202,10 @@ shell_curtain_create_view(struct shell_helper *helper, pos.c = weston_coord(0, 0); weston_view_set_position(view, pos); // weston_surface_set_color(surface, 0.0, 0.0, 0.0, 0.7); - weston_layer_entry_insert(&helper->curtain_layer.view_list, - &view->layer_link); +// weston_layer_entry_insert(&helper->curtain_layer.view_list, +// &view->layer_link); + weston_view_move_to_layer(view, &helper->curtain_layer.view_list); + pixman_region32_init_rect(&surface->input, 0, 0, surface->width, surface->height); @@ -1360,8 +1360,9 @@ shell_helper_move_background_surface( struct weston_view, surface_link); - //weston_layer_entry_remove(&existing_view->layer_link); - weston_layer_entry_insert(&shell->background_layer.view_list, &existing_view->layer_link); + +// weston_layer_entry_insert(&shell->background_layer.view_list, &existing_view->layer_link); + weston_view_move_to_layer(existing_view, &shell->background_layer.view_list); weston_compositor_schedule_repaint(shell->compositor); return; @@ -1385,7 +1386,6 @@ shell_helper_move_background_surface( } - static const struct shell_helper_interface helper_implementation = { shell_helper_move_surface, shell_helper_add_surface_to_layer, @@ -1450,7 +1450,7 @@ static void setup_shm(int shm_command) { int test = shm_command; memcpy((int*)ptr, &test, sizeof(int)); - memcpy(&test, (int *)ptr, sizeof(int)); + //memcpy(&test, (int *)ptr, sizeof(int)); weston_log("SHM is %d \n", test); } @@ -1499,8 +1499,6 @@ wet_module_init(struct weston_compositor *ec, return 0; } - - /** Begin exposay */ #ifndef container_of #define container_of(ptr, type, member) ({ \ @@ -1593,7 +1591,8 @@ exposay_activate(struct desktop_shell *shell) weston_view_geometry_dirty(esurface->view); weston_layer_entry_remove(&esurface->view->layer_link); - weston_layer_entry_insert(new_layer_link, &esurface->view->layer_link); +// weston_layer_entry_insert(new_layer_link, &esurface->view->layer_link); + weston_view_move_to_layer(esurface->view, new_layer_link); weston_view_geometry_dirty(esurface->view); weston_compositor_schedule_repaint(esurface->view->surface->compositor); @@ -1770,8 +1769,6 @@ exposay_create_mask(struct desktop_shell *shell, int width) { weston_view_move_to_layer(global_exposay.mask_view, &global_exposay.workspace->layer.view_list); -// weston_layer_entry_insert( &global_exposay.workspace->layer.view_list , -// &global_exposay.mask_view->layer_link); //weston_compositor_schedule_repaint(shell->compositor); @@ -1827,8 +1824,10 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output, if (!is_shell_surface(view->surface)) continue; - if (view->output != output) - continue; + if (view->output != output) { + printf("No output %p %p \n", view->output, output); + continue; + } add = wl_array_add(&global_exposay_views_array, sizeof *add); *add = view; @@ -1836,12 +1835,23 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output, } if(!hide_minimized) { + wl_list_for_each_safe(view, tmp, &shell->minimized_layer.view_list.link, layer_link.link) { - if (view->output != output) + + /* Broken since Weston 14.0 + TODO Test + */ + /* + + if (view->output != output) { + printf("No output %p %p \n", view->output, output); continue; + } + */ weston_layer_entry_remove(&view->layer_link); - weston_layer_entry_insert(&workspace->layer.view_list, &view->layer_link); + weston_view_move_to_layer(view, &workspace->layer.view_list); + add = wl_array_add(&global_minimized_array, sizeof *add); *add = view; @@ -1913,7 +1923,7 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output, int last_row = 1; wl_array_for_each(add, &global_exposay_views_array) { - view = *add; + view = *add; // if (!is_shell_surface(view->surface)) // continue; @@ -2343,8 +2353,6 @@ exposay_transition_active(struct desktop_shell *shell, int hide_minimized) weston_pointer_clear_focus(pointer); } - - wl_list_for_each(shell_output, &shell->output_list, link) { enum exposay_layout_state state; @@ -2415,26 +2423,11 @@ exposay_set_state(struct desktop_shell *shell, enum exposay_target_state state, } -/* - -static struct workspace * -get_workspace(struct desktop_shell *shell, unsigned int index) -{ - struct workspace **pws = shell->workspaces.array.data; - assert(index < shell->workspaces.num); - pws += index; - return *pws; -} - -*/ - struct workspace * get_current_workspace(struct desktop_shell *shell) { //Weston 11 removed workspaces return &shell->workspace; - -// return get_workspace(shell, shell->workspaces.current); } @@ -2468,7 +2461,9 @@ lower_fullscreen_layer(struct desktop_shell *shell, //only insert the actual surface //not the black view if (is_shell_surface(view->surface)) - weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); + weston_view_move_to_layer(view, &ws->layer.view_list); +// weston_layer_entry_insert(&ws->layer.view_list, &view->layer_link); + weston_view_damage_below(view); weston_surface_damage(view->surface); diff --git a/source/source/terminal.c b/source/source/terminal.c index 4abdb55..04cb03b 100644 --- a/source/source/terminal.c +++ b/source/source/terminal.c @@ -953,6 +953,30 @@ struct color_scheme DEFAULT_RED_COLORS = { {7, 0, 0, } /* bg:red (0), fg:light gray (7) */ }; +struct color_scheme DEFAULT_BLUE_COLORS = { + { + {0 , 0 , 0.66, 1}, /* blue */ + {0 , 0 , 0.66, 1}, /* red */ + {0 , 0.66, 0, 1}, /* green */ + {0.66, 0.33, 0, 1}, /* orange (nicer than muddy yellow) */ + {0 , 0 , 0.66, 1}, /* blue */ + {0.66, 0 , 0.66, 1}, /* magenta */ + {0, 0.66, 0.66, 1}, /* cyan */ + {1, 1, 1, 1}, /* white */ + {0.22, 0.33, 0.33, 1}, /* dark grey */ + {1, 0.33, 0.33, 1}, /* high red */ + {0.33, 1, 0.33, 1}, /* high green */ + {1, 1, 0.33, 1}, /* high yellow */ + {0.33, 0.33, 1, 1}, /* high blue */ + {1, 0.33, 1, 1}, /* high magenta */ + {0.33, 1, 1, 1}, /* high cyan */ + {1, 1, 1, 1} /* white */ + }, + 1, /* black border */ + {7, 0, 0, } /* bg:high blue (0), fg:light gray (7) */ +}; + + static void terminal_set_color(struct terminal *terminal, cairo_t *cr, int index) { @@ -2643,11 +2667,13 @@ key_handler(struct window *window, struct input *input, uint32_t time, /* Hide cursor, except if this was coming from a * repeating key press. */ + #if 0 serial = display_get_serial(terminal->display); if (terminal->hide_cursor_serial != serial) { input_set_pointer_image(input, CURSOR_BLANK); terminal->hide_cursor_serial = serial; } + #endif } } @@ -2797,6 +2823,9 @@ menu_func(void *data, struct input *input, int index) case 4: terminal_change_color(terminal, &DEFAULT_RED_COLORS); break; + case 5: + terminal_change_color(terminal, &DEFAULT_BLUE_COLORS); + break; } } @@ -2805,7 +2834,7 @@ show_menu(struct terminal *terminal, struct input *input, uint32_t time) { int32_t x, y; static const char *entries[] = { - "Open Terminal", "Copy", "Paste", "Minimize", "Red Color" + "Open Terminal", "Copy", "Paste", "Minimize", "Red", "Blue" }; input_get_position(input, &x, &y); diff --git a/source/source/wayward-shell.c b/source/source/wayward-shell.c index 493b7c6..0c8e540 100644 --- a/source/source/wayward-shell.c +++ b/source/source/wayward-shell.c @@ -105,7 +105,7 @@ typedef gint64 gfixed; #define WAYWARD_PANEL_LEAVE_BUG_Y 47 #define WAYWARD_ICON_SIZE 32 #define WAYWARD_AUDIO_STEP 3 -#define WAYWARD_BATTERY_X 345 +#define WAYWARD_BATTERY_X 69 #define WAYWARD_BATTERY_Y 30 //https://github.com/rev22/svgViewer/blob/master/svgViewer.c @@ -125,6 +125,7 @@ enum clock_state { CLOCK_SHOWN, SYSTEM_SHOWN, VOLUME_SHOWN, + BRIGHTNESS_SHOWN, CLOCK_NONE }; @@ -154,6 +155,14 @@ struct desktop { long current_volume; double current_volume_percentage; + int current_brightness; + bool enable_brightness_ddc; + int ddc_i2c_number; + bool enable_brightness_ctl; + char *brightnessctl_device; + + int right_icons; + struct toytimer shm_timer; struct panel *panel; @@ -161,6 +170,7 @@ struct desktop { struct weston_config *config; bool locking; + char *pincode; enum cursor_type grab_cursor; @@ -189,6 +199,7 @@ struct panel { struct output *owner; + struct window *window; struct widget *widget; struct wl_list launcher_list; @@ -207,16 +218,20 @@ struct panel { struct panel_launcher *volumeup_launcher; struct panel_label *volume_label; + struct panel_launcher *brightnessdown_launcher; + struct panel_launcher *brightnessup_launcher; + struct panel_label *brightness_label; int painted; int initial; int allocation_set; enum weston_desktop_shell_panel_position panel_position; enum clock_format clock_format; - enum clock_state clock_state; uint32_t color; + + struct desktop *desktop; }; struct background { @@ -392,6 +407,7 @@ enum shm_command { static void panel_add_battery(struct panel *panel); static void launch_volume(struct panel_launcher *launcher); +static void launch_brightness(struct panel_launcher *launcher); static void launch_system(struct panel_launcher *launcher); void wayland_pointer_leave_cb(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface); @@ -463,6 +479,18 @@ check_desktop_ready(struct window *window) } } +static void clock_hide(struct panel_clock *clock) { + clock->force_x = WAYWARD_HIDE_X; + widget_set_allocation(clock->widget, + clock->force_x, + clock->panel->clock_allocation.y, + clock->panel->clock_allocation.width, + clock->panel->clock_allocation.height + ); +} +static void clock_show(struct widget *widget) { +} + static void panel_launcher_activate(struct panel_launcher *widget) { @@ -502,6 +530,10 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) struct rectangle allocation; cairo_t *cr; +// if(launcher->force_x == WAYWARD_HIDE_X) { +// return; +// } + cr = widget_cairo_create(launcher->panel->widget); widget_get_allocation(widget, &allocation); @@ -525,7 +557,8 @@ panel_launcher_redraw_handler(struct widget *widget, void *data) allocation.x = launcher->force_x; } - //printf("Launcher allocation x y %d %d \n", allocation.x, allocation.y); + if(launcher == launcher->panel->volumeup_launcher) + printf("Launcher allocation x y %d %d \n", allocation.x, allocation.y); //cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_set_source_surface(cr, launcher->icon, allocation.x, allocation.y); @@ -706,10 +739,8 @@ panel_redraw_handler(struct widget *widget, void *data) return; } - if(!panel->initial) { panel->initial = 1; - } cr = widget_cairo_create(panel->widget); @@ -816,6 +847,8 @@ panel_clock_redraw_handler(struct widget *widget, void *data) if (allocation.width == 0) return; + if(clock->panel->clock_state != CLOCK_SHOWN) + return; clock->panel->painted = 0; cr = widget_cairo_create(clock->panel->widget); @@ -838,7 +871,7 @@ panel_clock_redraw_handler(struct widget *widget, void *data) allocation.y += allocation.height / 2 - 1 + extents.height / 2; //cairo_move_to(cr, allocation.x + 1, allocation.y + 1); - //cairo_set_source_rgba(cr, 0, 0, 0, 0.85); + cairo_show_text(cr, string); cairo_move_to(cr, allocation.x, allocation.y); cairo_set_source_rgba(cr, 1, 1, 1, 0.85); @@ -932,15 +965,32 @@ panel_resize_handler(struct widget *widget, int y = 0; int w = height > width ? width : height; int h = w; - int horizontal = panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP || panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM; + int horizontal = + panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_TOP || panel->panel_position == WESTON_DESKTOP_SHELL_PANEL_POSITION_BOTTOM; int first_pad_h = horizontal ? 0 : DEFAULT_SPACING / 2; int first_pad_w = horizontal ? DEFAULT_SPACING / 2 : 0; int count = 0; - int _count = 0; - int _count2 = 5; + + static int right_icons = 0; + int _count2 = 0; struct rectangle allocation; + //Special allocation x for volume/system launchers + if(!right_icons) { + wl_list_for_each(launcher, &panel->launcher_list, link) { + if(launcher->offset_right) { + right_icons++; + } + } + right_icons++; + } + _count2 = right_icons; + panel->desktop->right_icons = right_icons; + + printf("_count2 is %d \n", _count2); + if(!panel->allocation_set) { + wl_list_for_each(launcher, &panel->launcher_list, link) { //Special case for shutdown/volume icons if(!launcher->initial_x) { @@ -951,10 +1001,12 @@ panel_resize_handler(struct widget *widget, w + first_pad_w + 1, h + first_pad_h + 1); } - if (horizontal) - x += w + first_pad_w; - else + if (horizontal) { + if(launcher->initial_x != WAYWARD_HIDE_X) + x += w + first_pad_w; + } else { y += h + first_pad_h; + } first_pad_h = first_pad_w = 0; count++; } @@ -972,6 +1024,7 @@ panel_resize_handler(struct widget *widget, if (panel->clock) { + if(!panel->clock->force_x) widget_set_allocation(panel->clock->widget, x, y, w + 1, h + 1); @@ -984,10 +1037,10 @@ panel_resize_handler(struct widget *widget, widget_get_allocation(panel->clock->widget, &allocation); - //Special allocation x for volume/system launchers - if(!panel->allocation_set) { + +// if(!panel->allocation_set) { wl_list_for_each(launcher, &panel->launcher_list, link) { - //if( (_count >= count - 8) && (_count < count - 4) ) { + if(launcher->offset_right) { widget_get_allocation(launcher->widget, &allocation); launcher->force_x = panel->clock_allocation.x - 20 - allocation.width * _count2; @@ -996,10 +1049,13 @@ panel_resize_handler(struct widget *widget, _count2--; } - _count++; } - } + // } + + } + + printf("_count2 is %d 1 \n", _count2); panel->allocation_set = 1; } @@ -1097,6 +1153,7 @@ panel_create(struct desktop *desktop, struct output *output) panel = xzalloc(sizeof *panel); panel->owner = output; + panel->desktop = desktop; panel->base.configure = panel_configure; panel->window = window_create_custom(desktop->display); panel->widget = window_add_widget(panel->window, panel); @@ -1126,6 +1183,7 @@ panel_create(struct desktop *desktop, struct output *output) if (panel->clock_format != CLOCK_FORMAT_NONE) { panel->clock_state = CLOCK_SHOWN; panel_add_clock(panel); + if(global_battery_exists) panel_add_battery(panel); } @@ -1446,9 +1504,11 @@ load_icon_svg_or_fallback(const char *icon) return surface; } -static struct panel_launcher *panel_add_launcher(struct panel *panel, const char *icon, - const char *path, int initial_x, void (*function)(struct panel_launcher *widget) - ) +static struct panel_launcher *panel_add_launcher(struct panel *panel, + const char *icon, + const char *path, int initial_x, + void (*function)(struct panel_launcher *widget) + ) { struct panel_launcher *launcher; char *start, *p, *eq, **ps; @@ -1456,6 +1516,8 @@ static struct panel_launcher *panel_add_launcher(struct panel *panel, const char launcher = xzalloc(sizeof *launcher); + launcher->panel = panel; + if (strstr(icon, ".png") != NULL) { launcher->icon = load_icon_or_fallback(icon); launcher->icon = _cairo_image_surface_scale_nearest(launcher->icon, WAYWARD_ICON_SIZE, WAYWARD_ICON_SIZE); @@ -1480,6 +1542,7 @@ static struct panel_launcher *panel_add_launcher(struct panel *panel, const char //move special launchers to the right if(!launcher->initial_x) launcher->offset_right = 1; + } @@ -1526,6 +1589,8 @@ static struct panel_launcher *panel_add_launcher(struct panel *panel, const char ps = wl_array_add(&launcher->argv, sizeof *ps); *ps = NULL; + + launcher->panel = panel; wl_list_insert(panel->launcher_list.prev, &launcher->link); @@ -1999,6 +2064,13 @@ unlock_dialog_finish(struct task *task, uint32_t events) weston_desktop_shell_unlock(desktop->shell); unlock_dialog_destroy(desktop->unlock_dialog); desktop->unlock_dialog = NULL; + + shell_helper_set_panel (desktop->helper, desktop->panel->wl_surface); + shell_helper_move_surface (desktop->helper, + desktop->panel->wl_surface, + WAYWARD_NO_MOVE_X, global_desktop_height - WAYWARD_INITIAL_HEIGHT + ); + printf("Unlocked \n"); } static void @@ -2292,9 +2364,6 @@ output_init(struct output *output, struct desktop *desktop) //Set panel initial position if(!output->panel->wl_surface) exit(1); - printf("3 \n"); - - printf("4 \n"); @@ -2425,6 +2494,8 @@ void wayland_pointer_leave_cb(void *data, launch_volume(global_desktop->panel->volumeup_launcher); } else if(global_desktop->panel->clock_state == SYSTEM_SHOWN) { launch_system(global_desktop->panel->volumeup_launcher); + } else if(global_desktop->panel->clock_state == BRIGHTNESS_SHOWN) { + launch_brightness(global_desktop->panel->brightnessup_launcher); } window_schedule_resize(global_desktop->panel->window, global_desktop_width, 50); @@ -2443,11 +2514,6 @@ void wayland_pointer_motion_cb(void *data, } - - - - - void wayland_pointer_button_cb(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) @@ -2691,6 +2757,7 @@ static void setup_mixer (struct desktop *desktop) void check_battery_exists() { #if 0 + //TESTING global_battery_exists = 1; sprintf(global_battery_path, "/sys/class/power_supply/BAT0/capacity"); @@ -2851,9 +2918,7 @@ panel_battery_redraw_handler(struct widget *widget, void *data) padding_right = 15; } - allocation.x = battery->panel->clock_allocation.x - WAYWARD_BATTERY_X - padding_right; - - + allocation.x = battery->panel->clock_allocation.x - battery->panel->desktop->right_icons * WAYWARD_BATTERY_X - padding_right; allocation.y = WAYWARD_BATTERY_Y; cairo_show_text(cr, string); @@ -2920,39 +2985,32 @@ static void launch_system(struct panel_launcher *launcher) { struct rectangle widget_allocation; cairo_t *cr; - if(launcher->panel->clock_state == VOLUME_SHOWN) { launch_volume(launcher); + } else if(launcher->panel->clock_state == BRIGHTNESS_SHOWN) { + launch_brightness(launcher); } widget_get_allocation(launcher->panel->reboot_launcher->widget, &widget_allocation); if(launcher->panel->clock_state == CLOCK_SHOWN) { - launcher->panel->clock->force_x = WAYWARD_HIDE_X; launcher->panel->reboot_launcher->force_x = launcher->panel->clock_allocation.x; launcher->panel->shutdown_launcher->force_x = launcher->panel->clock_allocation.x + 48; + launcher->panel->reboot_launcher->initial_x = launcher->panel->clock_allocation.x; launcher->panel->shutdown_launcher->initial_x = launcher->panel->clock_allocation.x + 48; launcher->panel->clock_state = SYSTEM_SHOWN; + clock_hide(launcher->panel->clock); + } else { launcher->panel->clock->force_x = 0; launcher->panel->reboot_launcher->force_x = WAYWARD_HIDE_X; launcher->panel->shutdown_launcher->force_x = WAYWARD_HIDE_X; launcher->panel->clock_state = CLOCK_SHOWN; - + printf("Hiding system \n"); } - - - widget_set_allocation(launcher->panel->clock->widget, - launcher->panel->clock->force_x, - launcher->panel->clock_allocation.y, - launcher->panel->clock_allocation.width, - launcher->panel->clock_allocation.height - ); - - widget_set_allocation(launcher->panel->reboot_launcher->widget, launcher->panel->reboot_launcher->force_x, widget_allocation.y, @@ -2967,18 +3025,53 @@ static void launch_system(struct panel_launcher *launcher) { widget_allocation.height ); - + //TODO + launcher->panel->painted = 0; widget_schedule_redraw(launcher->panel->reboot_launcher->widget); widget_schedule_redraw(launcher->panel->shutdown_launcher->widget); widget_schedule_redraw(launcher->panel->clock->widget); window_schedule_resize(global_desktop->panel->window, global_desktop_width, 50); } +static void panel_brightness_label_redraw_handler(struct widget *widget, void *data) { -static void panel_volume_label_redraw_handler(struct widget *widget, void *data) { + cairo_t *cr; + struct rectangle allocation; + cairo_text_extents_t extents; + char string[7]; + struct panel_label *label = data; + if(label->panel->clock_state != BRIGHTNESS_SHOWN) + return; + sprintf(string, "%d", label->panel->desktop->current_brightness); + label->panel->painted = 0; + cr = widget_cairo_create(label->panel->widget); + cairo_set_font_size(cr, 20); + + cairo_select_font_face (cr, "Droid Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + + cairo_text_extents(cr, string, &extents); + + allocation.x = label->panel->clock_allocation.x; + allocation.y = 31; + + if(label->force_x) + allocation.x = label->force_x; + + printf("Brightness label drawn annotation x y %d \n", allocation.x, allocation.y); + + cairo_move_to(cr, allocation.x, 31); + cairo_set_source_rgba(cr, 1, 1, 1, 1); + cairo_show_text(cr, string); + cairo_destroy(cr); + +} + +static void panel_volume_label_redraw_handler(struct widget *widget, void *data) { cairo_t *cr; struct rectangle allocation; @@ -3033,7 +3126,7 @@ static struct panel_label *panel_add_volume_label(struct panel *panel) return label; } -static void launch_volume(struct panel_launcher *launcher) { +static void launch_brightness(struct panel_launcher *launcher) { struct rectangle allocation; struct rectangle widget_allocation; @@ -3042,23 +3135,100 @@ static void launch_volume(struct panel_launcher *launcher) { widget_get_allocation(launcher->panel->reboot_launcher->widget, &widget_allocation); + printf("Brightness shown 0 %d \n", launcher->panel->desktop->current_brightness); + if(launcher->panel->clock_state == SYSTEM_SHOWN) { launch_system(launcher); + } else if(launcher->panel->clock_state == VOLUME_SHOWN) { + launch_volume(launcher); } + + + if(launcher->panel->clock_state == CLOCK_SHOWN) { + + + + if(launcher->panel->desktop->current_brightness == 100) { + label_padding = 41; + } + + printf("Brightness shown 1 %d \n", launcher->panel->desktop->current_brightness); + + clock_hide(launcher->panel->clock); + launcher->panel->brightnessdown_launcher->force_x = launcher->panel->clock_allocation.x; + launcher->panel->brightnessup_launcher->force_x = launcher->panel->clock_allocation.x + 84; + launcher->panel->brightnessdown_launcher->initial_x = launcher->panel->clock_allocation.x; + launcher->panel->brightnessup_launcher->initial_x = launcher->panel->clock_allocation.x + 84; + //brightness label + launcher->panel->brightness_label->force_x = launcher->panel->clock_allocation.x + label_padding; + launcher->panel->clock_state = BRIGHTNESS_SHOWN; + + } else { + launcher->panel->clock->force_x = 0; + launcher->panel->brightnessdown_launcher->force_x = WAYWARD_HIDE_X; + launcher->panel->brightnessup_launcher->force_x = WAYWARD_HIDE_X; + launcher->panel->brightness_label->force_x = WAYWARD_HIDE_X; + launcher->panel->clock_state = CLOCK_SHOWN; + } + + widget_set_allocation(launcher->panel->brightnessdown_launcher->widget, + launcher->panel->brightnessdown_launcher->force_x, + widget_allocation.y, + widget_allocation.width, + widget_allocation.height + ); + + widget_set_allocation(launcher->panel->brightnessup_launcher->widget, + launcher->panel->brightnessup_launcher->force_x, + widget_allocation.y, + widget_allocation.width, + widget_allocation.height + ); + + widget_set_allocation(launcher->panel->brightness_label->widget, + launcher->panel->brightness_label->force_x, + widget_allocation.y, + 40, + 50 + ); + + widget_schedule_redraw(launcher->panel->brightnessdown_launcher->widget); + widget_schedule_redraw(launcher->panel->brightnessup_launcher->widget); + widget_schedule_redraw(launcher->panel->brightness_label->widget); + + widget_schedule_redraw(launcher->panel->clock->widget); + window_schedule_resize(launcher->panel->window, global_desktop_width, 50); +} + +static void launch_volume(struct panel_launcher *launcher) { + + struct rectangle allocation; + struct rectangle widget_allocation; + cairo_t *cr; + int label_padding = 45; + + widget_get_allocation(launcher->panel->volumeup_launcher->widget, &widget_allocation); + + if(launcher->panel->clock_state == SYSTEM_SHOWN) { + launch_system(launcher); + } else if(launcher->panel->clock_state == BRIGHTNESS_SHOWN) { + launch_brightness(launcher); + } + + if(launcher->panel->clock_state == CLOCK_SHOWN) { if(global_desktop->current_volume_percentage == 100) { label_padding = 41; } - printf("Volume Clock shown \n"); - launcher->panel->clock->force_x = WAYWARD_HIDE_X; + + clock_hide(launcher->panel->clock); launcher->panel->volumedown_launcher->force_x = launcher->panel->clock_allocation.x; launcher->panel->volumeup_launcher->force_x = launcher->panel->clock_allocation.x + 84; launcher->panel->volumedown_launcher->initial_x = launcher->panel->clock_allocation.x; launcher->panel->volumeup_launcher->initial_x = launcher->panel->clock_allocation.x + 84; //volume label launcher->panel->volume_label->force_x = launcher->panel->clock_allocation.x + label_padding; - launcher->panel->clock_state = VOLUME_SHOWN; } else { @@ -3067,15 +3237,10 @@ static void launch_volume(struct panel_launcher *launcher) { launcher->panel->volumeup_launcher->force_x = WAYWARD_HIDE_X; launcher->panel->volume_label->force_x = WAYWARD_HIDE_X; launcher->panel->clock_state = CLOCK_SHOWN; - } - widget_set_allocation(launcher->panel->clock->widget, - launcher->panel->clock->force_x, - launcher->panel->clock_allocation.y, - launcher->panel->clock_allocation.width, - launcher->panel->clock_allocation.height - ); + printf("Hiding volume \n"); + } widget_set_allocation(launcher->panel->volumedown_launcher->widget, launcher->panel->volumedown_launcher->force_x, @@ -3091,6 +3256,8 @@ static void launch_volume(struct panel_launcher *launcher) { widget_allocation.height ); + + widget_set_allocation(launcher->panel->volume_label->widget, launcher->panel->volume_label->force_x, widget_allocation.y, @@ -3196,8 +3363,11 @@ clock_restart () execl ("/usr/bin/sudo", "/usr/bin/sudo", "/usr/bin/systemctl", "reboot", (char *)0); } -static void brightnessctl (int dir) { - printf("Brightness up %d \n", dir); + +static void set_brightness_ctl (int brightness, char *brightnessctl_device ) { + char c[7]; + char dev[70]; + pid_t pid; pid = fork(); if (pid < 0) { @@ -3208,32 +3378,136 @@ static void brightnessctl (int dir) { if (pid) return; - if (setsid() == -1) exit(EXIT_FAILURE); + sprintf(c, "%d%%", brightness); + sprintf(dev, "--device=%s", brightnessctl_device); + + char *newargv[] = { "/usr/bin/brightnessctl", "s", c, dev, "", NULL }; + execve(newargv[0], newargv, environ); + +} + +static void set_brightness_ddc (int brightness, int ddc_i2c_number) { + char c[7]; + char dev[70]; + + pid_t pid; + pid = fork(); + if (pid < 0) { + fprintf(stderr, "fork failed: %s\n", strerror(errno)); + return; + } + + if (pid) + return; + + if (setsid() == -1) { + printf("ddcontrol failed \n"); + return; + } + + sprintf(c, "-w %d", brightness); + sprintf(dev, "dev:/dev/i2c-%d", ddc_i2c_number); + execl ("/usr/bin/ddccontrol", "/usr/bin/ddccontrol", "-r 0x10", c, dev, (char *)0); + return; + + // char *newargv[] = { "/usr/bin/ddccontrol", " -r 0x10 -w 12 dev:/dev/i2c-3", NULL }; +// execve(newargv[0], newargv, environ); + +} +static void brightness_up (struct panel_launcher *launcher) { + int brightness = launcher->panel->desktop->current_brightness + 5; + if(brightness > 100) + brightness = 100; + + if(brightness == launcher->panel->desktop->current_brightness) + return; + + printf("Brightness up %d \n", launcher->panel->desktop->current_brightness); + + if(launcher->panel->desktop->enable_brightness_ddc) + set_brightness_ddc (brightness, launcher->panel->desktop->ddc_i2c_number); + else + set_brightness_ctl (brightness, launcher->panel->desktop->brightnessctl_device); + + launcher->panel->desktop->current_brightness = brightness; + +} + +static void brightness_down (struct panel_launcher *launcher) { + int brightness = launcher->panel->desktop->current_brightness - 5; + if(brightness < 0) + brightness = 0; + + if(brightness == launcher->panel->desktop->current_brightness) + return; -// char *argv[] = {"/usr/bin/brightnessctl", "s", "5+", " > /tmp/d1", NULL}; -// posix_spawn(&pid, "/usr/bin/brightnessctl", NULL, NULL, argv, environ); + if(launcher->panel->desktop->enable_brightness_ddc) + set_brightness_ddc (brightness, launcher->panel->desktop->ddc_i2c_number); + else + set_brightness_ctl (brightness, launcher->panel->desktop->brightnessctl_device); -// return; + launcher->panel->desktop->current_brightness = brightness; + printf("Brightness down %d \n", brightness); - if(dir > 0) { - char *newargv[] = { "/usr/bin/brightnessctl", "s", "5%+", "", NULL }; - execve(newargv[0], newargv, environ); +} + +//Keyboard brightnessctl +static void brightnessctl (int dir) { + char c[7]; + char dev[70]; + int brightness = global_desktop->current_brightness; + + if(!global_desktop->enable_brightness_ctl) + return; + + if(dir != 1) { + brightness = brightness - 5; + if(brightness < 0) + brightness = 0; } else { - char *newargv[] = { "/usr/bin/brightnessctl", "s", "5%-", "", NULL }; - execve(newargv[0], newargv, environ); + brightness = brightness + 5; + if(brightness > 100) + brightness = 100; } -} + (*global_desktop).current_brightness = brightness; + + pid_t pid; + pid = fork(); + if (pid < 0) { + fprintf(stderr, "fork failed: %s\n", strerror(errno)); + return; + } + + if (pid) + return; + + if (setsid() == -1) + exit(EXIT_FAILURE); + + + printf("Brightness set to %d 0 \n", brightness); + sprintf(c, "%d%%", brightness); + sprintf(dev, ""); + + if(global_desktop->brightnessctl_device) + sprintf(dev, "--device=%s", global_desktop->brightnessctl_device); + + execl ("/usr/bin/brightnessctl", "/usr/bin/brightnessctl", "s", c, dev, (char *)0); + //char *newargv[] = { "/usr/bin/brightnessctl", "s", c, dev, "", NULL }; + //execve(newargv[0], newargv, environ); + +} + static void check_shm_commands(struct toytimer *tt) { char name[70]; - static int shm_init = 0; static void *ptr = NULL; static int shm_fd = 0; @@ -3292,6 +3566,112 @@ static void check_shm_commands(struct toytimer *tt) { +//TODO add launchers with icons +//TODO add svg +static int wayward_add_brightness(struct panel *panel, struct desktop *desktop) +{ + int brightness = 0; + char *icon = NULL; + char *path = NULL; + char *line = NULL; + char *hide_apps = NULL; + char *hide_apps_token, *hide_apps_str, *hide_apps_tofree; + struct panel_label *label = NULL; + char path_buf[1256]; + char ddc_buf[128]; + char ctl_buf[256]; + + printf("Adding brightness %d \n", desktop->enable_brightness_ddc); + + //Run script to get brightness + //TODO use C instead + if(desktop->enable_brightness_ddc && desktop->ddc_i2c_number + && desktop->ddc_i2c_number < 30 + ) { + + snprintf(ddc_buf, sizeof ddc_buf, "/usr/bin/bash /usr/lib/weston/wayward-get-brightness-ddc %d", + desktop->ddc_i2c_number); + + if( system ( ddc_buf ) ) { + printf("Brightness ddcontrol. error occured %s \n", strerror(errno)); + return -1; + } + } else if (desktop->enable_brightness_ctl && + desktop->brightnessctl_device + ) { + + snprintf(ctl_buf, sizeof ctl_buf, "/usr/bin/bash /usr/lib/weston/wayward-get-brightness-ctl %s", + desktop->brightnessctl_device); + + if(system ( ctl_buf )) { + printf("Brightnessctl. error occured %s \n", strerror(errno)); + return -1; + } + } else { + return -1; + } + + snprintf(path_buf, sizeof path_buf, "%s/.cache/wayward-brightness", getenv("HOME")); + + FILE* file = fopen(path_buf, "r"); + if(!file) { + return -1; + } + + fscanf (file, "%d", &brightness); + while (!feof (file)) + { + printf ("%d ", brightness); + fscanf (file, "%d", &brightness); + } + fclose (file); + + if(brightness > 100 || brightness < 0) { + return -1; + } + + panel_add_launcher(panel, + "/usr/share/wayward/display-brightness-symbolic.svg", + "", + 0, + launch_brightness + ); + + label = xzalloc(sizeof *label); + label->force_x = 0; + label->panel = panel; + label->widget = widget_add_widget(panel->widget, label); + widget_set_redraw_handler(label->widget, panel_brightness_label_redraw_handler); + panel->brightness_label = label; + + //Add plus/minus buttons + panel->brightnessdown_launcher = panel_add_launcher(panel, + "/usr/share/wayward/list-remove-symbolic.svg", + "", + WAYWARD_HIDE_X, + brightness_down + ); + panel->brightnessup_launcher = panel_add_launcher(panel, + "/usr/share/wayward/list-add-symbolic.svg", + "", + WAYWARD_HIDE_X, + brightness_up + ); + + + + panel->brightnessdown_launcher->force_x = WAYWARD_HIDE_X; + panel->brightnessup_launcher->force_x = WAYWARD_HIDE_X; + panel->brightness_label->force_x = WAYWARD_HIDE_X; + widget_schedule_redraw(panel->brightnessdown_launcher->widget); + widget_schedule_redraw(panel->brightnessup_launcher->widget); + widget_schedule_redraw(panel->brightness_label->widget); + + printf("Adding brightness %d \n", brightness); + return brightness; +} + + //TODO add launchers with icons //TODO add svg static int wayward_add_launchers(struct panel *panel, struct desktop *desktop) @@ -3303,11 +3683,22 @@ static int wayward_add_launchers(struct panel *panel, struct desktop *desktop) char *line = NULL; char *hide_apps = NULL; char *hide_apps_token, *hide_apps_str, *hide_apps_tofree; + bool hide_all_apps = false; size_t len = 0; ssize_t read; struct weston_config_section *s; + + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + + weston_config_section_get_bool(s, "hide-all-apps", &hide_all_apps, false); + + //Disable adding apps from /usr/share/local/applications + if(hide_all_apps) + return 0; + + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); weston_config_section_get_string(s, "hide-apps", &hide_apps, NULL); @@ -3432,9 +3823,25 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) struct rectangle clock_allocation; struct rectangle launcher_allocation; + bool disable_sound_icons = false; + struct panel_label *label = NULL; + + + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + weston_config_section_get_bool(s, "disable-sound-icons", &disable_sound_icons, false); + + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + weston_config_section_get_bool(s, "enable-brightness-ddc", &desktop->enable_brightness_ddc, false); + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + weston_config_section_get_int(s, "ddc-i2c-number", &desktop->ddc_i2c_number, 0); + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + weston_config_section_get_bool(s, "enable-brightness-ctl", &desktop->enable_brightness_ctl, false); + + s = weston_config_get_section(desktop->config, "shell", NULL, NULL); + weston_config_section_get_string(s, "brightnessctl-device", &desktop->brightnessctl_device, false); count = 0; @@ -3460,7 +3867,6 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) //Add launchers from /usr/share/applications shared_launchers = wayward_add_launchers(panel, desktop); - if (shared_launchers == 0 && count == 0) { /* add default launcher */ panel_add_launcher(panel, @@ -3478,60 +3884,63 @@ panel_add_launchers(struct panel *panel, struct desktop *desktop) //Action launchers panel_add_launcher(panel, "/usr/share/wayward/tv-symbolic.svg", - BINDIR "/weston-terminal", + "", 0, toggle_inhibit ); panel_add_launcher(panel, "/usr/share/wayward/open-menu-symbolic.svg", - BINDIR "/weston-terminal", + "", 0, launch_exposay ); panel_add_launcher(panel, "/usr/share/wayward/emblem-system-symbolic.svg", - BINDIR "/weston-terminal", + "", 0, launch_system ); - if(global_desktop->mixer_handle != NULL) { + //Add brightness + desktop->current_brightness = wayward_add_brightness(panel, desktop); + + if(desktop->mixer_handle != NULL && !disable_sound_icons) { panel_add_launcher(panel, "/usr/share/wayward/multimedia-volume-control-symbolic.svg", - BINDIR "/weston-terminal", + "", 0, launch_volume ); } //Add Restart button for system section - panel->reboot_launcher = panel_add_launcher(panel, "/usr/share/wayward/system-reboot-symbolic.svg", - BINDIR "/weston-terminal", + "", WAYWARD_HIDE_X, clock_restart ); + + //Add Shutdown button panel->shutdown_launcher = panel_add_launcher(panel, "/usr/share/wayward/system-shutdown-symbolic.svg", - BINDIR "/weston-terminal", + "", WAYWARD_HIDE_X, clock_shutdown ); - panel->reboot_launcher->force_x = WAYWARD_HIDE_X; panel->shutdown_launcher->force_x = WAYWARD_HIDE_X; - widget_schedule_redraw(panel->reboot_launcher->widget); - widget_schedule_redraw(panel->shutdown_launcher->widget); - if(!global_desktop->mixer_handle) + + + if(!global_desktop->mixer_handle || disable_sound_icons) return; //Add plus/minus button diff --git a/source/source/window.c b/source/source/window.c index b5735fb..c910ac4 100644 --- a/source/source/window.c +++ b/source/source/window.c @@ -89,6 +89,8 @@ typedef void *EGLContext; #define ZWP_POINTER_CONSTRAINTS_V1_VERSION 1 #define DEFAULT_XCURSOR_SIZE 32 +#define WAYWARD_HIDE_X 43371 + struct shm_pool; @@ -1634,6 +1636,8 @@ widget_find_widget(struct widget *widget, int32_t x, int32_t y) + + if (widget->viewport_dest_width != -1 && widget->viewport_dest_height != -1) { scale = widget->viewport_dest_width / (double) width; @@ -5414,10 +5418,10 @@ menu_redraw_handler(struct widget *widget, void *data) cairo_rectangle(cr, x, y, width, height); cairo_fill(cr); - cairo_select_font_face(cr, "sans", + cairo_select_font_face(cr, "Droid Sans Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(cr, 12); + cairo_set_font_size(cr, 14); for (i = 0; i < menu->count; i++) { if (i == menu->current) {