summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 9c7699a53721496a459e75411755de8b475e9f47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
pkgname=swscreenshot-gui
pkgver=3.0.0
pkgrel=1
pkgdesc="Screenshot app GUI for SwayWM"
arch=('x86_64')
url="https://gitlab.com/ricardoca/swscreenshot-gui"
license=('GPL')
depends=('gtk3' 'python-gobject' 'grim' 'slurp' 'wl-clipboard')
makedepends=('git')
source=("git+https://gitlab.com/ricardoca/swscreenshot-gui.git")
sha256sums=('SKIP')

package() {
  cd "$srcdir/$pkgname"

  # Install the Python script to system directory
  install -Dm755 "swscreenshot-gui.py" "$pkgdir/usr/share/$pkgname/swscreenshot-gui.py"

  # Create launcher script
  install -Dm755 /dev/null "$pkgdir/usr/bin/$pkgname"
  cat >"$pkgdir/usr/bin/$pkgname" <<EOF
#!/bin/bash

# Create config directory if it doesn't exist
mkdir -p "\$HOME/.config/$pkgname"

# Copy the script to user's config directory if it doesn't exist
if [ ! -f "\$HOME/.config/$pkgname/swscreenshot-gui.py" ]; then
  cp "/usr/share/$pkgname/swscreenshot-gui.py" "\$HOME/.config/$pkgname/"
  chmod +x "\$HOME/.config/$pkgname/swscreenshot-gui.py"
fi

# Run the script
python "\$HOME/.config/$pkgname/swscreenshot-gui.py"
EOF

  # Create setup script
  install -Dm755 /dev/null "$pkgdir/usr/bin/$pkgname-setup"
  cat >"$pkgdir/usr/bin/$pkgname-setup" <<EOF
#!/bin/bash

# Create config directory if it doesn't exist
mkdir -p "\$HOME/.config/$pkgname"

# Copy the script to user's config directory if it doesn't exist
if [ ! -f "\$HOME/.config/$pkgname/swscreenshot-gui.py" ]; then
  cp "/usr/share/$pkgname/swscreenshot-gui.py" "\$HOME/.config/$pkgname/"
  chmod +x "\$HOME/.config/$pkgname/swscreenshot-gui.py"
fi

# Modify sway config
SWAY_CONFIG="\$HOME/.config/sway/config"
if [ -f "\$SWAY_CONFIG" ]; then
  # Add floating window rule if not present
  if ! grep -q 'for_window \[title="Sway Screenshot GUI"\] floating enable, border normal' "\$SWAY_CONFIG"; then
    echo 'for_window [title="Sway Screenshot GUI"] floating enable, border normal' >> "\$SWAY_CONFIG"
    echo "Added floating window rule to Sway config"
  fi
  
  # Replace existing Print binding or add new one
  if grep -q 'bindsym Print exec grim' "\$SWAY_CONFIG"; then
    sed -i 's|bindsym Print exec grim|bindsym Print exec "python \$HOME/.config/$pkgname/swscreenshot-gui.py"|' "\$SWAY_CONFIG"
    echo "Updated Print key binding in Sway config"
  else
    echo 'bindsym Print exec "python \$HOME/.config/$pkgname/swscreenshot-gui.py"' >> "\$SWAY_CONFIG"
    echo "Added Print key binding to Sway config"
  fi
  
  echo "Sway configuration updated. Please run 'swaymsg reload' for changes to take effect."
else
  echo "Warning: Sway config not found at \$SWAY_CONFIG"
  echo "Please add the following lines to your Sway config manually:"
  echo 'for_window [title="Sway Screenshot GUI"] floating enable, border normal'
  echo 'bindsym Print exec "python \$HOME/.config/$pkgname/swscreenshot-gui.py"'
fi
EOF

  # Create desktop entry
  install -Dm644 /dev/null "$pkgdir/usr/share/applications/$pkgname.desktop"
  cat >"$pkgdir/usr/share/applications/$pkgname.desktop" <<EOF
[Desktop Entry]
Name=Sway Screenshot
Comment=Screenshot tool for Sway
Exec=/usr/bin/$pkgname
Terminal=false
Type=Application
Categories=Utility;Graphics;
Keywords=screenshot;screen;capture;
EOF

  # Add readme
  install -Dm644 /dev/null "$pkgdir/usr/share/doc/$pkgname/README.md"
  cat >"$pkgdir/usr/share/doc/$pkgname/README.md" <<EOF
# Sway Screenshot GUI

A simple GUI tool for taking screenshots in Sway window manager.

## Setup

After installation, run the setup script to configure Sway:

\`\`\`
$pkgname-setup
\`\`\`

This will:
1. Create necessary config files
2. Configure Sway to make the screenshot window float
3. Bind the Print key to launch the screenshot app

After setup, reload Sway with:
\`\`\`
swaymsg reload
\`\`\`

## Usage

Press the Print key to open the screenshot GUI, or run:
\`\`\`
$pkgname
\`\`\`

EOF
}