Skip to content

Commit

Permalink
Merge pull request #1 from ErikReider/master
Browse files Browse the repository at this point in the history
pull: Display image inside of indicator mortie#89
  • Loading branch information
DRAGONTOS authored Jan 21, 2024
2 parents a863c2f + 2104fd4 commit c7197f7
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 302 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# For the full list of code style requirements, see sway's CONTRIBUTING.md

root = true

[*]
charset = utf-8
end_of_line = lf

[*.{c,h,cmake,txt}]
indent_style = tab
indent_size = 4

[*.{xml,yml}]
indent_style = space
indent_size = 2

[config]
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
- push
- pull_request

jobs:
build:
name: Build on Alpine ${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- x86_64
- aarch64
- armv7
- ppc64le
- riscv64
steps:
- name: Checkout repository
uses: actions/checkout@v1

- name: Install latest Alpine Linux for ${{ matrix.arch }}
uses: jirutka/setup-alpine@v1
with:
arch: ${{ matrix.arch }}
branch: ${{ matrix.arch == 'riscv64' && 'edge' || 'latest-stable' }}
packages: >
build-base
cairo-dev
libxkbcommon-dev
linux-pam-dev
meson
scdoc
wayland-dev
wayland-protocols
- name: Build
run: |
meson -Dgdk-pixbuf=disabled . output
meson compile -C output --verbose
shell: alpine.sh {0}
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ which adds built-in screenshots and image manipulation effects like blurring.
It's inspired by [i3lock-color](https://github.com/PandorasFox/i3lock-color),
although the feature sets aren't perfectly overlapping.

![Screenshot](https://raw.githubusercontent.com/mortie/swaylock-effects/master/screenshot.png)
This repository ([jirutka/swaylock-effects](https://github.com/jirutka/swaylock-effects))
is a fork of [mortie/swaylock-effects](https://github.com/mortie/swaylock-effects)
which is no longer maintained.

![Screenshot](https://raw.githubusercontent.com/jirutka/swaylock-effects/master/screenshot.png)

## Example Command

Expand Down Expand Up @@ -63,14 +67,32 @@ The main new features compared to upstream swaylock are:
New feature ideas are welcome as issues (though I may never get around to
implement them), new feature implementations are welcome as pull requests :)

## Versions

swaylock-effects continuously incorporates changes from the original [swaylock](https://github.com/swaywm/swaylock).
The following table shows the relation between the swaylock-effect and swaylock versions.

| swaylock-effects | swaylock (original) |
| ---------------- | --------------------------------------------------------------------------------------------------- |
| 1.6-0 | [1.5](https://github.com/swaywm/swaylock/tree/1.5) |
| 1.6-1 | 1.5-7-g[a99afe6a](https://github.com/swaywm/swaylock/tree/a99afe6a7075c962da72b140f02e18318052d833) |
| 1.6-2 | 1.5-9-g[235b925d](https://github.com/swaywm/swaylock/tree/235b925df7e1bb82d98f1ac8c02e8f85d0a54ee9) |
| 1.6-3 | 1.5-9-g[235b925d](https://github.com/swaywm/swaylock/tree/235b925df7e1bb82d98f1ac8c02e8f85d0a54ee9) |
| 1.6.10 | [1.6](https://github.com/swaywm/swaylock/tree/1.6) |


## Installation

### From Packages

* Alpine Linux: [swaylock-effects](https://pkgs.alpinelinux.org/packages?name=swaylock-effects)
* Arch Linux (AUR): [swaylock-effects-git](https://aur.archlinux.org/packages/swaylock-effects-git/)
* Arch Linux (AUR): [swaylock-effects](https://aur.archlinux.org/packages/swaylock-effects/) / [swaylock-effects-git](https://aur.archlinux.org/packages/swaylock-effects-git/)

The original [mortie/swaylock-effects](https://github.com/mortie/swaylock-effects) (now unmaintained)
has been packaged for:

* Fedora (Copr): [swaylock-effects](https://copr.fedorainfracloud.org/coprs/eddsalkield/swaylock-effects/)
(originally by Edd Salkield, now looking for a new maintainer)
(thanks to Edd Salkield)
* FreeBSD: [swaylock-effects](https://www.freshports.org/x11/swaylock-effects/)
* Gentoo (GURU overlay): [swaylock-effects](https://gpo.zugaina.org/Overlays/guru/gui-apps/swaylock-effects)
* T2 SDE: [swaylock-effects](https://t2sde.org/packages/swaylock-effects)
Expand Down
115 changes: 105 additions & 10 deletions background-image.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#define _DEFAULT_SOURCE
#include <assert.h>
#include "background-image.h"
#include "cairo.h"
#include "log.h"
#include "swaylock.h"

#ifdef __FreeBSD__
# include <sys/endian.h>
#else
# include <endian.h>
#endif

// Cairo RGB24 uses 32 bits per pixel, as XRGB, in native endianness.
// xrgb32_le uses 32 bits per pixel, as XRGB, little endian (BGRX big endian).
void cairo_rgb24_from_xrgb32_le(unsigned char *buf, int width, int height, int stride) {
Expand Down Expand Up @@ -32,6 +39,58 @@ void cairo_rgb24_from_xbgr32_le(unsigned char *buf, int width, int height, int s
}
}

void cairo_rgb24_from_xrgb2101010_le(unsigned char *buf, int width, int height, int stride) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
uint32_t *pix = (uint32_t *) (buf + y * stride + x * 4);
uint32_t color = le32toh(*pix);
*pix = 0 |
((color >> 22) & 0xFF) << 16 |
((color >> 12) & 0xFF) << 8 |
((color >> 2) & 0xFF);
}
}
}

void cairo_rgb24_from_xbgr2101010_le(unsigned char *buf, int width, int height, int stride) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
uint32_t *pix = (uint32_t *) (buf + y * stride + x * 4);
uint32_t color = le32toh(*pix);
*pix = 0 |
((color >> 2) & 0xFF) << 16 |
((color >> 12) & 0xFF) << 8 |
((color >> 22) & 0xFF);
}
}
}

void cairo_rgb24_from_rgbx1010102_le(unsigned char *buf, int width, int height, int stride) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
uint32_t *pix = (uint32_t *) (buf + y * stride + x * 4);
uint32_t color = le32toh(*pix);
*pix = 0 |
((color >> 24) & 0xFF) << 16 |
((color >> 14) & 0xFF) << 8 |
((color >> 4) & 0xFF);
}
}
}

void cairo_rgb24_from_bgrx1010102_le(unsigned char *buf, int width, int height, int stride) {
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
uint32_t *pix = (uint32_t *) (buf + y * stride + x * 4);
uint32_t color = le32toh(*pix);
*pix = 0 |
((color >> 4) & 0xFF) << 16 |
((color >> 14) & 0xFF) << 8 |
((color >> 24) & 0xFF);
}
}
}

enum background_mode parse_background_mode(const char *mode) {
if (strcmp(mode, "stretch") == 0) {
return BACKGROUND_MODE_STRETCH;
Expand Down Expand Up @@ -163,19 +222,54 @@ cairo_surface_t *load_background_from_buffer(void *buf, uint32_t format,
break;
}

if (format == WL_SHM_FORMAT_XBGR8888 || format == WL_SHM_FORMAT_ABGR8888) {
switch (format) {
case WL_SHM_FORMAT_XBGR8888:
case WL_SHM_FORMAT_ABGR8888:
cairo_rgb24_from_xbgr32_le(
cairo_image_surface_get_data(image),
cairo_image_surface_get_width(image),
cairo_image_surface_get_height(image),
cairo_image_surface_get_stride(image));
} else {
if (format != WL_SHM_FORMAT_XRGB8888 && format != WL_SHM_FORMAT_ARGB8888) {
swaylock_log(LOG_ERROR,
"Unknown pixel format: %u. Assuming XRGB32. Colors may look wrong.",
format);
}

break;
case WL_SHM_FORMAT_XRGB2101010:
case WL_SHM_FORMAT_ARGB2101010:
cairo_rgb24_from_xrgb2101010_le(
cairo_image_surface_get_data(image),
cairo_image_surface_get_width(image),
cairo_image_surface_get_height(image),
cairo_image_surface_get_stride(image));
break;
case WL_SHM_FORMAT_XBGR2101010:
case WL_SHM_FORMAT_ABGR2101010:
cairo_rgb24_from_xbgr2101010_le(
cairo_image_surface_get_data(image),
cairo_image_surface_get_width(image),
cairo_image_surface_get_height(image),
cairo_image_surface_get_stride(image));
break;
case WL_SHM_FORMAT_RGBX1010102:
case WL_SHM_FORMAT_RGBA1010102:
cairo_rgb24_from_rgbx1010102_le(
cairo_image_surface_get_data(image),
cairo_image_surface_get_width(image),
cairo_image_surface_get_height(image),
cairo_image_surface_get_stride(image));
break;
case WL_SHM_FORMAT_BGRX1010102:
case WL_SHM_FORMAT_BGRA1010102:
cairo_rgb24_from_bgrx1010102_le(
cairo_image_surface_get_data(image),
cairo_image_surface_get_width(image),
cairo_image_surface_get_height(image),
cairo_image_surface_get_stride(image));
break;
default:
swaylock_log(LOG_ERROR,
"Unknown pixel format: %u. Assuming XRGB32. Colors may look wrong.",
format);
// fallthrough
case WL_SHM_FORMAT_XRGB8888:
case WL_SHM_FORMAT_ARGB8888: {
// If we're little endian, we don't have to do anything
int test = 1;
bool is_little_endian = *(char *)&test == 1;
Expand All @@ -187,6 +281,7 @@ cairo_surface_t *load_background_from_buffer(void *buf, uint32_t format,
cairo_image_surface_get_stride(image));
}
}
}

return image;
}
Expand Down Expand Up @@ -223,7 +318,7 @@ cairo_surface_t *load_background_image(const char *path) {
}

void render_background_image(cairo_t *cairo, cairo_surface_t *image,
enum background_mode mode, int buffer_width, int buffer_height) {
enum background_mode mode, int buffer_width, int buffer_height, double alpha) {
double width = cairo_image_surface_get_width(image);
double height = cairo_image_surface_get_height(image);

Expand Down Expand Up @@ -285,6 +380,6 @@ void render_background_image(cairo_t *cairo, cairo_surface_t *image,
assert(0);
break;
}
cairo_paint(cairo);
cairo_paint_with_alpha(cairo, alpha);
cairo_restore(cairo);
}
14 changes: 14 additions & 0 deletions cairo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <cairo/cairo.h>
#include "cairo.h"
#if HAVE_GDK_PIXBUF
Expand Down Expand Up @@ -29,6 +31,18 @@ cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel)
return CAIRO_SUBPIXEL_ORDER_DEFAULT;
}

cairo_surface_t *cairo_surface_duplicate(cairo_surface_t *src) {
uint32_t stride = cairo_image_surface_get_stride(src);
uint32_t height = cairo_image_surface_get_height(src);
uint32_t width = cairo_image_surface_get_width(src);
cairo_format_t format = cairo_image_surface_get_format(src);

void *new_data = malloc(stride * height);
memcpy(new_data, cairo_image_surface_get_data(src), stride * height);

return cairo_image_surface_create_for_data(new_data, format, width, height, stride);
}

#if HAVE_GDK_PIXBUF
cairo_surface_t* gdk_cairo_image_surface_create_from_pixbuf(const GdkPixbuf *gdkbuf) {
int chan = gdk_pixbuf_get_n_channels(gdkbuf);
Expand Down
3 changes: 2 additions & 1 deletion completions/bash/swaylock
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ _swaylock()
--indicator-thickness
--indicator-x-position
--indicator-y-position
--indicator-image
--inside-caps-lock-color
--inside-clear-color
--inside-color
Expand Down Expand Up @@ -99,7 +100,7 @@ _swaylock()
COMPREPLY=($(compgen -W "${scaling[*]}" -- "$cur"))
return
;;
-i|--image)
-i|--image|--indicator-image)
if grep -q : <<< "$cur"; then
output="${cur%%:*}:"
cur="${cur#*:}"
Expand Down
1 change: 1 addition & 0 deletions completions/fish/swaylock.fish
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ complete -c swaylock -l indicator-radius --description "Sets the indi
complete -c swaylock -l indicator-thickness --description "Sets the indicator thickness."
complete -c swaylock -l indicator-x-position --description "Sets the horizontal position of the indicator."
complete -c swaylock -l indicator-y-position --description "Sets the vertical position of the indicator."
complete -c swaylock -l indicator-image --description "Display the given image inside of the indicator."
complete -c swaylock -l inside-caps-lock-color --description "Sets the color of the inside of the indicator when Caps Lock is active."
complete -c swaylock -l inside-clear-color --description "Sets the color of the inside of the indicator when cleared."
complete -c swaylock -l inside-color --description "Sets the color of the inside of the indicator."
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_swaylock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ _arguments -s \
'(--indicator-thickness)'--indicator-thickness'[Sets the indicator thickness]:thickness:' \
'(--indicator-x-position)'--indicator-x-position'[Sets the horizontal position of the indicator]' \
'(--indicator-y-position)'--indicator-y-position'[Sets the vertical position of the indicator]' \
'(--indicator-image)'--indicator-image'[Display the given image inside of the indicator]:filename:_files' \
'(--inside-caps-lock-color)'--inside-caps-lock-color'[Sets the color of the inside of the indicator when Caps Lock is active]:color:' \
'(--inside-clear-color)'--inside-clear-color'[Sets the color of the inside of the indicator when cleared]:color:' \
'(--inside-color)'--inside-color'[Sets the color of the inside of the indicator]:color:' \
Expand Down
Loading

0 comments on commit c7197f7

Please sign in to comment.