diff --git a/meson.build b/meson.build index 18d25f191..ddbf2391c 100644 --- a/meson.build +++ b/meson.build @@ -1,27 +1,27 @@ project( - 'sway', - 'c', - version: '0.2', - license: 'MIT', - meson_version: '>=0.60.0', - default_options: [ - 'c_std=c11', - 'warning_level=2', - 'werror=true', - ], + 'sway', + 'c', + version: '0.2', + license: 'MIT', + meson_version: '>=0.60.0', + default_options: [ + 'c_std=c11', + 'warning_level=2', + 'werror=true', + ], ) add_project_arguments( - [ - '-DWLR_USE_UNSTABLE', - - '-Wno-unused-parameter', - '-Wno-unused-result', - '-Wno-missing-braces', - '-Wundef', - '-Wvla', - ], - language: 'c', + [ + '-DWLR_USE_UNSTABLE', + + '-Wno-unused-parameter', + '-Wno-unused-result', + '-Wno-missing-braces', + '-Wundef', + '-Wvla', + ], + language: 'c', ) cc = meson.get_compiler('c') @@ -32,16 +32,16 @@ sysconfdir = get_option('sysconfdir') prefix = get_option('prefix') if is_freebsd - add_project_arguments('-D_C11_SOURCE', language: 'c') + add_project_arguments('-D_C11_SOURCE', language: 'c') endif # Execute the wlroots subproject, if any wlroots_version = ['>=0.16.0', '<0.17.0'] subproject( - 'wlroots', - default_options: ['examples=false'], - required: false, - version: wlroots_version, + 'wlroots', + default_options: ['examples=false'], + required: false, + version: wlroots_version, ) jsonc = dependency('json-c', version: '>=0.13') @@ -74,37 +74,37 @@ xcb_icccm = dependency('xcb-icccm', required: get_option('xwayland')) threads = dependency('threads') # for pthread_setschedparam wlroots_features = { - 'xwayland': false, + 'xwayland': false, } foreach name, _ : wlroots_features - var_name = 'have_' + name.underscorify() - have = wlroots.get_variable(pkgconfig: var_name, internal: var_name) == 'true' - wlroots_features += { name: have } + var_name = 'have_' + name.underscorify() + have = wlroots.get_variable(pkgconfig: var_name, internal: var_name) == 'true' + wlroots_features += { name: have } endforeach if get_option('xwayland').enabled() and not wlroots_features['xwayland'] - error('Cannot enable Xwayland in sway: wlroots has been built without Xwayland support') + error('Cannot enable Xwayland in sway: wlroots has been built without Xwayland support') endif have_xwayland = xcb.found() and xcb_icccm.found() and wlroots_features['xwayland'] if get_option('sd-bus-provider') == 'auto' - if not get_option('tray').disabled() - assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') - endif - sdbus = dependency(['libsystemd', 'libelogind'], - required: false, - version: '>=239', - ) - if not sdbus.found() - sdbus = dependency('basu', required: false) - endif + if not get_option('tray').disabled() + assert(get_option('auto_features').auto(), 'sd-bus-provider must not be set to auto since auto_features != auto') + endif + sdbus = dependency(['libsystemd', 'libelogind'], + required: false, + version: '>=239', + ) + if not sdbus.found() + sdbus = dependency('basu', required: false) + endif else - sdbus = dependency(get_option('sd-bus-provider'), required: get_option('tray')) + sdbus = dependency(get_option('sd-bus-provider'), required: get_option('tray')) endif tray_deps_found = sdbus.found() if get_option('tray').enabled() and not tray_deps_found - error('Building with -Dtray=enabled, but sd-bus has not been not found') + error('Building with -Dtray=enabled, but sd-bus has not been not found') endif have_tray = (not get_option('tray').disabled()) and tray_deps_found @@ -119,42 +119,42 @@ conf_data.set10('HAVE_TRAY', have_tray) scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages')) if scdoc.found() - scdoc_prog = find_program(scdoc.get_variable(pkgconfig: 'scdoc'), native: true) - mandir = get_option('mandir') - man_files = [ - 'sway/sway.1.scd', - 'sway/sway.5.scd', - 'sway/sway-bar.5.scd', - 'sway/sway-input.5.scd', - 'sway/sway-ipc.7.scd', - 'sway/sway-output.5.scd', - 'swaybar/swaybar-protocol.7.scd', - 'swaymsg/swaymsg.1.scd', - ] - - if get_option('swaynag') - man_files += [ - 'swaynag/swaynag.1.scd', - 'swaynag/swaynag.5.scd', - ] - endif - - foreach filename : man_files - topic = filename.split('.')[-3].split('/')[-1] - section = filename.split('.')[-2] - output = '@0@.@1@'.format(topic, section) - - custom_target( - output, - input: filename, - output: output, - command: scdoc_prog, - install: true, - feed: true, - capture: true, - install_dir: '@0@/man@1@'.format(mandir, section) - ) - endforeach + scdoc_prog = find_program(scdoc.get_variable(pkgconfig: 'scdoc'), native: true) + mandir = get_option('mandir') + man_files = [ + 'sway/sway.1.scd', + 'sway/sway.5.scd', + 'sway/sway-bar.5.scd', + 'sway/sway-input.5.scd', + 'sway/sway-ipc.7.scd', + 'sway/sway-output.5.scd', + 'swaybar/swaybar-protocol.7.scd', + 'swaymsg/swaymsg.1.scd', + ] + + if get_option('swaynag') + man_files += [ + 'swaynag/swaynag.1.scd', + 'swaynag/swaynag.5.scd', + ] + endif + + foreach filename : man_files + topic = filename.split('.')[-3].split('/')[-1] + section = filename.split('.')[-2] + output = '@0@.@1@'.format(topic, section) + + custom_target( + output, + input: filename, + output: output, + command: scdoc_prog, + install: true, + feed: true, + capture: true, + install_dir: '@0@/man@1@'.format(mandir, section) + ) + endforeach endif add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'c') @@ -162,15 +162,15 @@ add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir version = '"@0@"'.format(meson.project_version()) git = find_program('git', native: true, required: false) if git.found() - git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'], check: false) - git_branch = run_command([git, 'rev-parse', '--abbrev-ref', 'HEAD'], check: false) - if git_commit.returncode() == 0 and git_branch.returncode() == 0 - version = '"@0@-@1@ (" __DATE__ ", branch \'@2@\')"'.format( - meson.project_version(), - git_commit.stdout().strip(), - git_branch.stdout().strip(), - ) - endif + git_commit = run_command([git, 'rev-parse', '--short', 'HEAD'], check: false) + git_branch = run_command([git, 'rev-parse', '--abbrev-ref', 'HEAD'], check: false) + if git_commit.returncode() == 0 and git_branch.returncode() == 0 + version = '"@0@-@1@ (" __DATE__ ", branch \'@2@\')"'.format( + meson.project_version(), + git_commit.stdout().strip(), + git_branch.stdout().strip(), + ) + endif endif add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c') @@ -181,34 +181,34 @@ relative_dir_parts = [] i = 0 in_prefix = true foreach p : build_root - if i >= source_root.length() or not in_prefix or p != source_root[i] - in_prefix = false - relative_dir_parts += '..' - endif - i += 1 + if i >= source_root.length() or not in_prefix or p != source_root[i] + in_prefix = false + relative_dir_parts += '..' + endif + i += 1 endforeach i = 0 in_prefix = true foreach p : source_root - if i >= build_root.length() or not in_prefix or build_root[i] != p - in_prefix = false - relative_dir_parts += p - endif - i += 1 + if i >= build_root.length() or not in_prefix or build_root[i] != p + in_prefix = false + relative_dir_parts += p + endif + i += 1 endforeach relative_dir = join_paths(relative_dir_parts) + '/' # Strip relative path prefixes from the code if possible, otherwise hide them. if cc.has_argument('-fmacro-prefix-map=/prefix/to/hide=') - add_project_arguments( - '-fmacro-prefix-map=@0@='.format(relative_dir), - language: 'c', - ) + add_project_arguments( + '-fmacro-prefix-map=@0@='.format(relative_dir), + language: 'c', + ) else - add_project_arguments( - '-DSWAY_REL_SRC_DIR="@0@"'.format(relative_dir), - language: 'c', - ) + add_project_arguments( + '-DSWAY_REL_SRC_DIR="@0@"'.format(relative_dir), + language: 'c', + ) endif @@ -221,13 +221,13 @@ subdir('sway') subdir('swaymsg') if get_option('swaybar') or get_option('swaynag') - subdir('client') + subdir('client') endif if get_option('swaybar') - subdir('swaybar') + subdir('swaybar') endif if get_option('swaynag') - subdir('swaynag') + subdir('swaynag') endif config = configuration_data() @@ -236,91 +236,90 @@ config.set('prefix', prefix) config.set('sysconfdir', join_paths(prefix, sysconfdir)) configure_file( - configuration: config, - input: 'config.in', - output: '@BASENAME@', - install_dir: join_paths(sysconfdir, 'sway') + configuration: config, + input: 'config.in', + output: '@BASENAME@', + install_dir: join_paths(sysconfdir, 'sway') ) install_data( - 'sway.desktop', - install_dir: join_paths(datadir, 'wayland-sessions') + 'sway.desktop', + install_dir: join_paths(datadir, 'wayland-sessions') ) if get_option('default-wallpaper') - wallpaper_files = files( - 'assets/Sway_Wallpaper_Blue_768x1024.png', - 'assets/Sway_Wallpaper_Blue_768x1024_Portrait.png', - 'assets/Sway_Wallpaper_Blue_1136x640.png', - 'assets/Sway_Wallpaper_Blue_1136x640_Portrait.png', - 'assets/Sway_Wallpaper_Blue_1366x768.png', - 'assets/Sway_Wallpaper_Blue_1920x1080.png', - 'assets/Sway_Wallpaper_Blue_2048x1536.png', - 'assets/Sway_Wallpaper_Blue_2048x1536_Portrait.png', - ) - wallpaper_install_dir = join_paths(datadir, 'backgrounds', 'sway') - - install_data(wallpaper_files, install_dir: wallpaper_install_dir) + wallpaper_files = files( + 'assets/Sway_Wallpaper_Blue_768x1024.png', + 'assets/Sway_Wallpaper_Blue_768x1024_Portrait.png', + 'assets/Sway_Wallpaper_Blue_1136x640.png', + 'assets/Sway_Wallpaper_Blue_1136x640_Portrait.png', + 'assets/Sway_Wallpaper_Blue_1366x768.png', + 'assets/Sway_Wallpaper_Blue_1920x1080.png', + 'assets/Sway_Wallpaper_Blue_2048x1536.png', + 'assets/Sway_Wallpaper_Blue_2048x1536_Portrait.png', + ) + wallpaper_install_dir = join_paths(datadir, 'backgrounds', 'sway') + + install_data(wallpaper_files, install_dir: wallpaper_install_dir) endif if get_option('zsh-completions') - zsh_files = files( - 'completions/zsh/_sway', - 'completions/zsh/_swaymsg', - ) - zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions') + zsh_files = files( + 'completions/zsh/_sway', + 'completions/zsh/_swaymsg', + ) + zsh_install_dir = join_paths(datadir, 'zsh', 'site-functions') - install_data(zsh_files, install_dir: zsh_install_dir) + install_data(zsh_files, install_dir: zsh_install_dir) endif if get_option('bash-completions') - bash_files = files( - 'completions/bash/sway', - 'completions/bash/swaymsg', - ) - - if get_option('swaybar') - bash_files += files('completions/bash/swaybar') - endif - - if bash_comp.found() - bash_install_dir = bash_comp.get_variable( - pkgconfig: 'completionsdir', - pkgconfig_define: ['datadir', datadir] - ) - else - bash_install_dir = join_paths(datadir, 'bash-completion', 'completions') - endif - - install_data(bash_files, install_dir: bash_install_dir) + bash_files = files( + 'completions/bash/sway', + 'completions/bash/swaymsg', + ) + + if get_option('swaybar') + bash_files += files('completions/bash/swaybar') + endif + + if bash_comp.found() + bash_install_dir = bash_comp.get_variable( + pkgconfig: 'completionsdir', + pkgconfig_define: ['datadir', datadir] + ) + else + bash_install_dir = join_paths(datadir, 'bash-completion', 'completions') + endif + + install_data(bash_files, install_dir: bash_install_dir) endif if get_option('fish-completions') - fish_files = files( - 'completions/fish/sway.fish', - 'completions/fish/swaymsg.fish', - ) - - if get_option('swaynag') - fish_files += files('completions/fish/swaynag.fish') - endif - - if fish_comp.found() - fish_install_dir = fish_comp.get_variable( - pkgconfig: 'completionsdir', - pkgconfig_define: ['datadir', datadir] - ) - else - fish_install_dir = join_paths(datadir, 'fish', 'vendor_completions.d') - endif - - install_data(fish_files, install_dir: fish_install_dir) + fish_files = files( + 'completions/fish/sway.fish', + 'completions/fish/swaymsg.fish', + ) + + if get_option('swaynag') + fish_files += files('completions/fish/swaynag.fish') + endif + + if fish_comp.found() + fish_install_dir = fish_comp.get_variable( + pkgconfig: 'completionsdir', + pkgconfig_define: ['datadir', datadir] + ) + else + fish_install_dir = join_paths(datadir, 'fish', 'vendor_completions.d') + endif + + install_data(fish_files, install_dir: fish_install_dir) endif summary({ - 'xwayland': have_xwayland, - 'gdk-pixbuf': gdk_pixbuf.found(), - 'tray': have_tray, - 'man-pages': scdoc.found(), + 'xwayland': have_xwayland, + 'gdk-pixbuf': gdk_pixbuf.found(), + 'tray': have_tray, + 'man-pages': scdoc.found(), }, bool_yn: true) - diff --git a/sway/desktop/fx_renderer.c b/sway/desktop/fx_renderer.c index 7ad209d79..feff39824 100644 --- a/sway/desktop/fx_renderer.c +++ b/sway/desktop/fx_renderer.c @@ -1,9 +1,8 @@ -// The original wlr_renderer was heavily referenced in making this project -// https://gitlab.freedesktop.org/wlroots/wlroots/-/tree/master/render/gles2 +/* + The original wlr_renderer was heavily referenced in making this project + https://gitlab.freedesktop.org/wlroots/wlroots/-/tree/master/render/gles2 +*/ -// TODO: add push / pop_gles2_debug(renderer)? - -#define _POSIX_C_SOURCE 200809L #include #include #include @@ -12,21 +11,21 @@ #include #include #include + #include "log.h" #include "sway/desktop/fx_renderer.h" #include "sway/output.h" #include "sway/server.h" // shaders +#include "box_shadow_frag_src.h" #include "common_vert_src.h" +#include "corner_frag_src.h" #include "quad_frag_src.h" #include "quad_round_frag_src.h" #include "quad_round_tl_frag_src.h" #include "quad_round_tr_frag_src.h" -#include "corner_frag_src.h" -#include "box_shadow_frag_src.h" -//#include "tex_frag_src.h" -#include "tex_decorated_frag_src.h" +#include "tex_frag_src.h" static const GLfloat verts[] = { 1, 0, // top right @@ -166,7 +165,7 @@ static GLuint link_program(const GLchar *frag_src, enum fx_gles2_shader_source s static bool link_tex_program(struct fx_renderer *renderer, struct gles2_tex_shader *shader, enum fx_gles2_shader_source source) { GLuint prog; - const GLchar *frag_src = tex_decorated_frag_src; + const GLchar *frag_src = tex_frag_src; shader->program = prog = link_program(frag_src, source); if (!shader->program) { diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/shaders/meson.build index ff5e04b2c..fdcbf4c95 100644 --- a/sway/desktop/shaders/meson.build +++ b/sway/desktop/shaders/meson.build @@ -8,7 +8,7 @@ shaders = [ 'quad_round_tr.frag', 'corner.frag', 'box_shadow.frag', - 'tex_decorated.frag', + 'tex.frag', ] foreach name : shaders diff --git a/sway/desktop/shaders/tex.frag b/sway/desktop/shaders/tex.frag index 3f5291378..40320f9b3 100644 --- a/sway/desktop/shaders/tex.frag +++ b/sway/desktop/shaders/tex.frag @@ -22,6 +22,15 @@ uniform sampler2D tex; #endif uniform float alpha; +uniform float dim; +uniform vec4 dim_color; +uniform vec2 size; +uniform vec2 position; +uniform float radius; +uniform bool has_titlebar; +uniform float saturation; + +const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721); vec4 sample_texture() { #if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL @@ -32,5 +41,23 @@ vec4 sample_texture() { } void main() { - gl_FragColor = sample_texture() * alpha; + vec4 color = sample_texture(); + // Saturation + if (saturation != 1.0) { + vec4 pixColor = texture2D(tex, v_texcoord); + vec3 irgb = pixColor.rgb; + vec3 target = vec3(dot(irgb, saturation_weight)); + color = vec4(mix(target, irgb, saturation), pixColor.a); + } + // Dimming + gl_FragColor = mix(color, dim_color, dim) * alpha; + + if (!has_titlebar || gl_FragCoord.y - position.y > radius) { + vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); + if (max(corner_distance.x, corner_distance.y) < radius) { + float d = radius - distance(corner_distance, vec2(radius)); + float smooth = smoothstep(-1.0f, 0.5f, d); + gl_FragColor = mix(vec4(0), gl_FragColor, smooth); + } + } } diff --git a/sway/desktop/shaders/tex_decorated.frag b/sway/desktop/shaders/tex_decorated.frag deleted file mode 100644 index 40320f9b3..000000000 --- a/sway/desktop/shaders/tex_decorated.frag +++ /dev/null @@ -1,63 +0,0 @@ -/* enum wlr_gles2_shader_source */ -#define SOURCE_TEXTURE_RGBA 1 -#define SOURCE_TEXTURE_RGBX 2 -#define SOURCE_TEXTURE_EXTERNAL 3 - -#if !defined(SOURCE) -#error "Missing shader preamble" -#endif - -#if SOURCE == SOURCE_TEXTURE_EXTERNAL -#extension GL_OES_EGL_image_external : require -#endif - -precision mediump float; - -varying vec2 v_texcoord; - -#if SOURCE == SOURCE_TEXTURE_EXTERNAL -uniform samplerExternalOES tex; -#elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX -uniform sampler2D tex; -#endif - -uniform float alpha; -uniform float dim; -uniform vec4 dim_color; -uniform vec2 size; -uniform vec2 position; -uniform float radius; -uniform bool has_titlebar; -uniform float saturation; - -const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721); - -vec4 sample_texture() { -#if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL - return texture2D(tex, v_texcoord); -#elif SOURCE == SOURCE_TEXTURE_RGBX - return vec4(texture2D(tex, v_texcoord).rgb, 1.0); -#endif -} - -void main() { - vec4 color = sample_texture(); - // Saturation - if (saturation != 1.0) { - vec4 pixColor = texture2D(tex, v_texcoord); - vec3 irgb = pixColor.rgb; - vec3 target = vec3(dot(irgb, saturation_weight)); - color = vec4(mix(target, irgb, saturation), pixColor.a); - } - // Dimming - gl_FragColor = mix(color, dim_color, dim) * alpha; - - if (!has_titlebar || gl_FragCoord.y - position.y > radius) { - vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); - if (max(corner_distance.x, corner_distance.y) < radius) { - float d = radius - distance(corner_distance, vec2(radius)); - float smooth = smoothstep(-1.0f, 0.5f, d); - gl_FragColor = mix(vec4(0), gl_FragColor, smooth); - } - } -}