Arch+wayland+swappy的错误记录

前言报错信息:


** (swappy:822983): WARNING **: 20:59:05.806: save_dir: failed to create '/root/Pictures/Screenshots'

** (swappy:822983): CRITICAL **: 20:59:07.615: unable to save drawing area to pixbuf: 打开“/root/Pictures/Screenshots/241110_11h55m22s_screenshot.png”进行写入失败:权限不够

在我用了一次(sudo swappy)后出现的问题。但是后来未在别的系统重建错误。

我在仿照大佬写一个截图脚本 莫名其妙出现错误。

#!/usr/bin/env bash

# Restores the shader after screenhot has been taken
function restore_shader() {
	if [ -n "$shader" ]; then
		hyprshade on "$shader"
	fi
}

# Saves the current shader and turns it off
shader=$(hyprshade current)
hyprshade off
trap restore_shader EXIT


# save_dir="${2:-$HOME/Pictures/Screenshots}"
save_dir="${2:-$HOME/Pictures/Screenshots}"
save_file=$(date +'%y%m%d_%Hh%Mm%Ss_screen.png')
swpy_dir="$HOME/.config/swappy"
mkdir -p $save_dir
mkdir -p $swpy_dir
echo -e "[Default]\nsave_dir=$save_dir\nsave_filename_format=$save_file" > $swpy_dir/config
echo $save_dir
temp_img="/tmp/screenshot.png"
rm -f "$temp_img"

function swappy_save_file() {
    swappy -f $temp_img
}

function print_error() {
cat <<"EOF"
    screenshot.sh <action>
    ...valid actions are...
        p : print all screens
        s : snip current screen
        f : snip current screen (frozen)
        m : print focused monitor
EOF
}

case $1 in
    p) # print all outputs
        grimblast copysave screen $temp_img && restore_shader && swappy_save_file ;;
    s) # drag to manually snip an area / click on a window to print it
        grimblast copysave area $temp_img && restore_shader && swappy_save_file ;;
    f) # frozen screen, drag to manually snip an area / click on a window to print it
        grimblast --freeze copysave area $temp_img && restore_shader && swappy_save_file ;;
    m) # print focused monitor
        grimblast copysave output $temp_img && restore_shader && swappy_save_file ;;
    *) # invalid option
        #grimblast copysave screen $temp_img && restore_shader && swappy_save_file ;;
        print_error ;;
esac

if [ -f "${save_dir}/${save_file}" ]; then
	notify-send -a "Screenshot" -i "${save_dir}/${save_file}" "${save_file}" "saved in ${save_dir}"
fi

简单调试后发现是swappy读取配置文件的问题 ,查阅各种教程发现swappy就是一个配置文件地址
 

"$XDG_CONFIG_HOME/swappy/config",
"$HOME/.config/swappy/config",

使用系统调用调试后发现'/root/Pictures/Screenshots' 出现的莫名其妙,找不到它在哪个配置文件里读取的。后面会贴出文件有大佬可以帮我分析一下。

strace -o swappy_trace.txt -f -e trace=all ./swappy -f ./1.png 

这里我还用了虚拟机arch系统yay了一个 ./swappy。 确定了是我系统的问题。

然后在我本机上新建里一个新用户运行swappy(保证所有个人配置文件为空)还是一样的错误。

就grep在系统里疯狂找各种文件是否有上文的错误信息。耗时长整体。

放弃了 只好git下载源文件自己编译。GitHub - jtheoof/swappy: A Wayland native snapshot editing tool, inspired by Snappy on macOS

/src/config.c中发现配置文件确实就这么多地方会去读取。


static char *get_default_save_dir() {
  static const char *storage_paths[] = {
      "$XDG_DESKTOP_DIR",
      "$XDG_CONFIG_HOME/Desktop",
      "$HOME/Desktop",
      "$HOME",
  };

  for (size_t i = 0; i < sizeof(storage_paths) / sizeof(char *); ++i) {
    wordexp_t p;
    if (wordexp(storage_paths[i], &p, 0) == 0) {
      char *path = g_strdup(p.we_wordv[0]);
      wordfree(&p);
      if (path && folder_exists(path)) {
        return path;
      }
      g_free(path);
    }
  }

  return NULL;
}

static char *get_config_file() {
  static const char *storage_paths[] = {
      "$XDG_CONFIG_HOME/swappy/config",
      "$HOME/.config/swappy/config",
  };

  for (size_t i = 0; i < sizeof(storage_paths) / sizeof(char *); ++i) {
    wordexp_t p;
    if (wordexp(storage_paths[i], &p, 0) == 0) {
      char *path = g_strdup(p.we_wordv[0]);
      wordfree(&p);
      if (path && file_exists(path)) {
        return path;
      }
      g_free(path);
    }
  }

  return NULL;

后面把可能读取的位置文件给注释重新编译。

终于锁定了  "$XDG_CONFIG_HOME/swappy/config"这个语句。

虽然我echo $XDG_CONFIG_HOME 已经打了无数遍都是没有输出。

那就重链接一下吧我真的不知道为什么会错。

发现问题到现在已经干了2天了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值