Skip to content

New feature: automatically save display settings in kanshi's config file.#11

Open
petertheprocess wants to merge 5 commits intoartizirk:masterfrom
petertheprocess:master
Open

New feature: automatically save display settings in kanshi's config file.#11
petertheprocess wants to merge 5 commits intoartizirk:masterfrom
petertheprocess:master

Conversation

@petertheprocess
Copy link
Copy Markdown

No description provided.

@alex-courtis
Copy link
Copy Markdown
Collaborator

Nice work!

@kRHYME7
Copy link
Copy Markdown

kRHYME7 commented Oct 11, 2023

Thanks! Nice Work

@sigboe
Copy link
Copy Markdown

sigboe commented Oct 22, 2023

I looked up wdisplays on github to request this very feature! So thank you!

But I am wondering if the readme should rather suggest launching kanshi from sway like this instead?

    exec kanshi
    exec_always kanshictl reload 

@sigboe
Copy link
Copy Markdown

sigboe commented Nov 23, 2023

I've been running this PR for a bit now, and I just want to say so far so good. The only thing I expected, keep in mind I do not have anything to say in this project, I am just a happy user. What I expected, is that there was an option in the hamburger menu button to enable or disable saving the config. Before switching to this PR, I thought that this is what the Automatically Apply Changes did. So I never turned it off prior to switching to this PR. When I activated this feature, then it became obvious that it was to not have to click the apply button.

But I think this PR, in my flawed knowledge opinion is probably makes wdisplays strictly better, and I hope it is merged! :)

This is my PKGBUILD file I used to make a package on Arch

pkgname=wdisplays-kanshi
_pkgname="wdisplays"
pkgver=r67.4411521
pkgrel=2
pkgdesc='GUI display configurator for wlroots compositors'
url='https://github.com/petertheprocess/wdisplays'
license=('GPL3')
provides=("$_pkgname")
conflicts=("$_pkgname")
arch=('i686' 'x86_64' 'armv6h' 'armv7h')
depends=('gtk3')
makedepends=('git' 'meson' 'gtk3' 'libepoxy' 'wayland' 'wayland-protocols')
source=("${_pkgname}::git+$url")
sha256sums=('SKIP')

pkgver() {
  cd "$_pkgname"
  ( set -o pipefail
    git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
  )
}

build() {
  cd "$_pkgname"
  arch-meson "$srcdir/build"
  ninja -C "$srcdir/build"
}

package() {
  DESTDIR="$pkgdir" ninja -C "$srcdir/build" install
  install -D -m 644 "$srcdir/wdisplays/resources/wdisplays.svg" "$pkgdir"/usr/share/pixmaps/wdisplays.svg
  install -D -m 644 "$srcdir/wdisplays/resources/wdisplays.desktop.in" "$pkgdir"/usr/share/applications/wdisplays.desktop
  install -d -m 755 "$pkgdir"/usr/share/licenses/"$_pkgname"
  install -D -m 644 "$_pkgname"/LICENSES/* "$pkgdir"/usr/share/licenses/"$_pkgname"/
}

To use this package, you put it in a folder, and run makepkg -sic, I derived it from the wdisplays-git

@sigboe
Copy link
Copy Markdown

sigboe commented Mar 11, 2024

After using this for an extended period I want to report back that there is one major change that should be done before merging this.

It needs two small changes to the code

this writes to kanshi's config file the (critiria or) name of the display with parenthesis behind with the connected port in them. So this parenthesis should not be added. With this parenthesis kanshi doesn't recognize the display.

Also if the name of the monitor contains characters that needs to be escaped. then the criteria should be single quoted instead of double quoted.

Comment thread .vscode/settings.json Outdated
Comment thread README.md Outdated
Comment thread src/store.c Outdated
Comment thread src/store.c Outdated
@petertheprocess
Copy link
Copy Markdown
Author

Thank you for the valuable advices @sigboe @JasonGantner. I am currently preparing for several final exams and also haven’t use this app for a while since I switched my OS back to popos for more stable work experience. But after the exams, I am glad to take your advices and test it.

@petertheprocess
Copy link
Copy Markdown
Author

petertheprocess commented May 31, 2024

this writes to kanshi's config file the (critiria or) name of the display with parenthesis behind with the connected port in them. So this parenthesis should not be added. With this parenthesis kanshi doesn't recognize the display.

I don't think it will be an issue, with this parenthesis, kanshi can recognize this display but treat them as 2 different display if using different port.

I have a laptop which support hdmi and also typec(DP), when I wanna use laptop's keyboard, I will connect my screen by typec. And if I wanna connect my keyboard by typec and put laptop on a stand, hdmi will used for my screen. With this patenthesis 'feature', I can restore my display layout setting automatically.

2. check $XDG_CONFIG_HOME before $HOME
3. all MAX SIZE now use platform-based macro from limits.h rather than magic number
@zipproth
Copy link
Copy Markdown

@sigboe was absolutely right about the parentheses issue. I've created a fix for this: petertheprocess#2

The problem is that kanshi cannot parse output descriptions containing parentheses like "Iiyama North America PL2294H2 1207823601758 (DP-3)". According to kanshi(5) manual, valid output criteria are either output names (DP-3) or manufacturer/model/serial without parentheses.

My fix changes store.c to use head->name instead of head->description, which resolves the "no profile matched" error and makes kanshi work correctly.

This should be applied to this PR as well to make the kanshi integration actually functional.

* wip

* Fix deprecated flag

* check config path only on startup

* use HEADS_MAX from wdisplays.h

* remove useless strcpy

* update readme and meson syntax

* clang-format

* Fix C23 issues

gcc 15 is more strict and compiles C by default with C23.  `noop` is
used as a default null initializer, but now it must have the correct
type, so add a cast.

See also: https://bugs.gentoo.org/946954

---------

Co-authored-by: Viorel Munteanu <ceamac@gentoo.org>
@JasonGantner
Copy link
Copy Markdown

@petertheprocess check my new PR for missing licensing information that need to be added

* Add partial licensing header

* add licensing info where needed

* Update SPDX header in store.c

---------

Co-authored-by: TanShaochang <30321432+petertheprocess@users.noreply.github.com>
@petertheprocess
Copy link
Copy Markdown
Author

petertheprocess commented Jul 8, 2025

@sigboe @zipproth

Sry about the parentheses issue, I was using the old version of Kanshi v1.2, I thought it is the latest but just found it had migrated from github to https://gitlab.freedesktop.org/emersion/kanshi and didn't get your points, now I figured it out, and would look into it for a best solution. Maybe a PR for Kanshi?

It is caused by that:
Starting with Kanshi 1.7, the match_profile_output function was updated to use fnmatch, which changes how output matching works compared to earlier versions (like 1.2.0 I had).

static bool match_profile_output(struct kanshi_profile_output *output,
		struct kanshi_head *head) {
	const char *make = head->make ? head->make : "Unknown";
	const char *model = head->model ? head->model : "Unknown";
	const char *serial_number =
		head->serial_number ? head->serial_number : "Unknown";

	char identifier[1024];
	assert(sizeof(identifier) >= strlen(make) + strlen(model) + strlen(serial_number) + 3);
	snprintf(identifier, sizeof(identifier), "%s %s %s", make, model, serial_number);

	return strcmp(output->name, "*") == 0 ||
		strcmp(output->name, head->name) == 0 ||
		fnmatch(output->name, identifier, 0) == 0;
}

petertheprocess#2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants