Skip to content

Commit

Permalink
Maximize QGIS when it starts
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Feb 16, 2024
1 parent 2becb59 commit 8c61c28
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ ENV DESKTOP_FILES_DIR /opt/desktop-files
ENV MIME_FILES_DIR /opt/mime-files
RUN mkdir -p ${DESKTOP_FILES_DIR} ${MIME_FILES_DIR}

# Enable the following line to allow the jovyan user to run sudo commands without a password
# RUN echo "jovyan ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN apt-get update && apt-get -y install wmctrl

USER ${NB_UID}

# Setup qgis
Expand All @@ -36,4 +40,6 @@ COPY qgis.desktop ${DESKTOP_FILES_DIR}/qgis.desktop
# See: https://manpages.ubuntu.com/manpages/focal/en/man1/xdg-autostart.1.html
COPY qgis.desktop /etc/xdg/autostart/qgis.desktop

COPY qgis.bash /home

COPY qgis.xml ${MIME_FILES_DIR}/qgis.xml
11 changes: 11 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'
services:
qgis:
image: qgis
build:
context: .
dockerfile: Dockerfile
ports:
- "8888:8888"
security_opt:
- seccomp:unconfined
27 changes: 27 additions & 0 deletions qgis.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -l

function maximize_qgis_window() {
# Set the desired size
desired_width=1680
desired_height=999 # or 1050
while true; do
window_id=$(wmctrl -l | grep 'QGIS' | awk '{print $1}')
if [ -n "$window_id" ]; then
window_info=$(wmctrl -lG | grep "$window_id")
width=$(echo "$window_info" | awk '{print $5}')
height=$(echo "$window_info" | awk '{print $6}')
if [ "$width" -lt "$desired_width" ] || [ "$height" -lt "$desired_height" ]; then
echo "QGIS window is smaller than $desired_width x $desired_height. Maximizing..."
wmctrl -i -r "$window_id" -b add,maximized_vert,maximized_horz
else
echo "QGIS window is at least $desired_width x $desired_height"
fi
else
echo "QGIS window not found"
fi
sleep 2
done
}

# Start QGIS
qgis & maximize_qgis_window
2 changes: 1 addition & 1 deletion qgis.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Name=QGIS Desktop
GenericName=Geographic Information System
Icon=/opt/conda/share/qgis/images/icons/qgis-icon-512x512.png
TryExec=qgis
Exec=qgis %F
Exec=/home/qgis.bash %F
Terminal=false
StartupNotify=false
Categories=Qt;Education;Science;Geography;
Expand Down

0 comments on commit 8c61c28

Please sign in to comment.