#global bootstrap 1

%if !0%{?bootstrap}
%ifnarch %{arm}
%global tests 1
%endif
%endif

Name:           kwin
Version:        5.26.4
Release:        1
Summary:        KDE Window manager

# all sources are effectively GPLv2+, except for:
# scripts/enforcedeco/contents/code/main.js
# KDE e.V. may determine that future GPL versions are accepted
License:        GPLv2 or GPLv3
URL:            https://userbase.kde.org/KWin
%global revision %(echo %{version} | cut -d. -f3)
%if %{revision} >= 50
%global majmin_ver %(echo %{version} | cut -d. -f1,2).50
%global stable unstable
%else
%global majmin_ver %(echo %{version} | cut -d. -f1,2)
%global stable stable
%endif
Source0:        http://download.kde.org/%{stable}/plasma/%{version}/%{name}-%{version}.tar.xz
# Base
BuildRequires:  extra-cmake-modules
BuildRequires:  kf5-rpm-macros
BuildRequires:  systemd

# Qt
BuildRequires:  qt5-qtbase-devel
BuildRequires:  qt5-qtbase-static
# KWinQpaPlugin (and others?)
BuildRequires:  qt5-qtbase-private-devel
BuildRequires:  qt5-qtsensors-devel
BuildRequires:  qt5-qtscript-devel
BuildRequires:  qt5-qttools-devel
BuildRequires:  qt5-qttools-static
BuildRequires:  qt5-qtx11extras-devel
BuildRequires:  qt5-qtwayland-devel

# X11/OpenGL
BuildRequires:  pkgconfig(libxcvt)
BuildRequires:  mesa-libGL-devel
BuildRequires:  mesa-libEGL-devel
BuildRequires:  mesa-libgbm-devel
BuildRequires:  libxkbcommon-devel
BuildRequires:  libX11-devel
BuildRequires:  libXi-devel
BuildRequires:  libxcb-devel
BuildRequires:  libICE-devel
BuildRequires:  libSM-devel
BuildRequires:  libXcursor-devel
BuildRequires:  xcb-util-wm-devel
BuildRequires:  xcb-util-image-devel
BuildRequires:  xcb-util-keysyms-devel
BuildRequires:  xcb-util-cursor-devel
BuildRequires:  xcb-util-devel
BuildRequires:  libepoxy-devel
BuildRequires:  libcap-devel

BuildRequires:  lcms2-devel
BuildRequires:  glib2-devel
BuildRequires:  pipewire-devel

# Wayland
BuildRequires:  kf5-kwayland-devel
BuildRequires:  wayland-devel
BuildRequires:  wayland-protocols-devel
BuildRequires:  libxkbcommon-devel >= 0.4
BuildRequires:  pkgconfig(libinput) >= 0.10
BuildRequires:  pkgconfig(libudev)

# KF5
BuildRequires:  kf5-kcompletion-devel
BuildRequires:  kf5-kconfig-devel
BuildRequires:  kf5-kconfigwidgets-devel
BuildRequires:  kf5-kcoreaddons-devel
BuildRequires:  kf5-kcrash-devel
BuildRequires:  kf5-kdbusaddons-devel
BuildRequires:  kf5-kglobalaccel-devel
BuildRequires:  kf5-ki18n-devel
BuildRequires:  kf5-kinit-devel >= 5.10.0-3
BuildRequires:  kf5-kio-devel
BuildRequires:  kf5-knotifications-devel
BuildRequires:  kf5-kservice-devel
BuildRequires:  kf5-plasma-devel
BuildRequires:  kf5-kwidgetsaddons-devel
BuildRequires:  kf5-kwindowsystem-devel
BuildRequires:  kf5-kdoctools-devel
BuildRequires:  kf5-kcmutils-devel
BuildRequires:  kf5-knewstuff-devel
BuildRequires:  kf5-kactivities-devel
BuildRequires:  kf5-kdoctools-devel
BuildRequires:  kf5-kdeclarative-devel
BuildRequires:  kf5-kiconthemes-devel
BuildRequires:  kf5-kidletime-devel
BuildRequires:  kf5-ktextwidgets-devel
BuildRequires:  kf5-kirigami2-devel
BuildRequires:  kf5-krunner-devel

BuildRequires:  kdecoration-devel >= %{majmin_ver}
BuildRequires:  kscreenlocker-devel >= %{majmin_ver}
BuildRequires:  plasma-breeze-devel >= %{majmin_ver}
BuildRequires:  plasma-wayland-protocols-devel

%if 0%{?tests}
BuildRequires: dbus-x11
BuildRequires: openbox
BuildRequires: xorg-x11-server-Xvfb
%endif

## Runtime deps
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       %{name}-common%{?_isa} = %{version}-%{release}
Requires:       kdecoration%{?_isa} >= %{majmin_ver}
Requires:       kscreenlocker%{?_isa} >= %{majmin_ver}

# Runtime-only dependencies
%if ! 0%{?bootstrap}
BuildRequires:  qt5-qtmultimedia-devel
BuildRequires:  qt5-qtvirtualkeyboard
%endif
Requires:       qt5-qtmultimedia%{?_isa}
Recommends:     qt5-qtvirtualkeyboard%{?_isa}
# libkdeinit5_kwin*
%{?kf5_kinit_requires}

# Before kwin was split out from kde-workspace into a subpackage
Conflicts:      kde-workspace%{?_isa} < 4.11.14-2

Obsoletes:      kwin-gles < 5
Obsoletes:      kwin-gles-libs < 5

# http://bugzilla.redhat.com/605675
# until initial-setup is fixed... (#1197135)
Provides: firstboot(windowmanager) = kwin

Recommends: %{name}-wayland = %{version}-%{release}
Requires:   %{name}-x11 = %{version}-%{release}
%description
%{summary}.

%package        wayland
Summary:        KDE Window Manager with Wayland support
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       %{name}-common%{?_isa} = %{version}-%{release}
Requires:       kwayland-integration%{?_isa} >= %{majmin_ver}
%if ! 0%{?bootstrap}
BuildRequires:  xorg-x11-server-Xwayland
%endif
Requires:       xorg-x11-server-Xwayland
# http://bugzilla.redhat.com/605675
Provides:       firstboot(windowmanager) = kwin_wayland
# KWinQpaPlugin (and others?)

# libkdeinit5_kwin*
%{?kf5_kinit_requires}
# Obsolete kwin-wayland-nvidia package as this is now done automatically
# by kwin-wayland
Obsoletes:      %{name}-wayland-nvidia < 5.20.2-2
Provides:       %{name}-wayland-nvidia = %{version}-%{release}
%description    wayland
%{summary}.

%package        x11
Summary:        KDE Window Manager with X11 support
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       %{name}-common%{?_isa} = %{version}-%{release}
%if ! 0%{?bootstrap}
BuildRequires:  xorg-x11-server-Xorg
%endif
Requires:       xorg-x11-server-Xorg
# http://bugzilla.redhat.com/605675
Provides:       firstboot(windowmanager) = kwin_x11
# KWinX11Platform (and others?)

# libkdeinit5_kwin*
%{?kf5_kinit_requires}
%description    x11
%{summary}.

%package        common
Summary:        Common files for KWin X11 and KWin Wayland
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       kf5-kwayland%{?_isa} >= %{_kf5_version}
# Split of X11 variant into subpackage
Obsoletes:      %{name}-common < 5.19.5-3
%description    common
%{summary}.

%package        libs
Summary:        KWin runtime libraries
# Before kwin-libs was split out from kde-workspace into a subpackage
Conflicts:      kde-workspace-libs%{?_isa} < 4.11.14-2
%description    libs
%{summary}.

%package        devel
Summary:        Development files for %{name}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       %{name}-common%{?_isa} = %{version}-%{release}
Requires:       kf5-kconfig-devel
Requires:       kf5-kservice-devel
Requires:       kf5-kwindowsystem-devel
Conflicts:      kde-workspace-devel < 5.0.0-1
%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.

%package        doc
Summary:        User manual for %{name}
Requires:       %{name} = %{version}-%{release}
BuildArch:      noarch
%description    doc
%{summary}.


%prep
%autosetup -p1

sed -i \
  -e 's|^find_package(Breeze ${PROJECT_VERSION} CONFIG)|find_package(Breeze 5.9 CONFIG)|' \
  CMakeLists.txt


%build
mkdir %{_target_platform}
pushd %{_target_platform}
%{cmake_kf5} .. \
  -DBUILD_TESTING:BOOL=%{?tests:ON}%{!?tests:OFF}
popd

%make_build -C %{_target_platform}


%install
make install/fast DESTDIR=%{buildroot} -C %{_target_platform}

%find_lang %{name} --with-html --all-name
grep "%{_kf5_docdir}" %{name}.lang > %{name}-doc.lang
cat %{name}.lang %{name}-doc.lang | sort | uniq -u > kwin5.lang

# temporary(?) hack to allow initial-setup to use /usr/bin/kwin too
ln -s kwin_x11 %{buildroot}%{_bindir}/kwin


%check
%if 0%{?tests}
# using low timeout to avoid extending buildtimes too much for now -- rex
export CTEST_OUTPUT_ON_FAILURE=1
xvfb-run -a \
dbus-launch --exit-with-session \
make test ARGS="--output-on-failure --timeout 10" -C %{_target_platform} ||:
%endif

%files
%{_bindir}/kwin

%files common -f kwin5.lang
%{_datadir}/kwin
%{_kf5_qtplugindir}/plasma/kcms/systemsettings/*.so
%{_kf5_qtplugindir}/plasma/kcms/systemsettings_qwidgets/*.so
%{_kf5_qtplugindir}/kwin/
%{_kf5_qtplugindir}/kpackage/packagestructure/
%{_kf5_qtplugindir}/org.kde.kdecoration2/*.so
%{_qt5_qmldir}/org/kde/kwin
%{_qt5_qmldir}/org/kde/kwin.2/qmldir
%{_qt5_qmldir}/org/kde/kwin.2/DesktopThumbnailItem.qml
%{_kf5_libdir}/kconf_update_bin/kwin5_update_default_rules
%{_libexecdir}/kwin_killer_helper
%{_libexecdir}/kwin_rules_dialog
%{_libexecdir}/kwin-applywindowdecoration
%{_datadir}/kconf_update/kwin.upd
%{_datadir}/kconf_update/kwin-5.16-auto-bordersize.sh
%{_datadir}/kconf_update/kwin-5.18-move-animspeed.py
%{_datadir}/kconf_update/kwin-5.21-desktop-grid-click-behavior.py
%{_datadir}/kconf_update/kwin-5.21-no-swap-encourage.py
%{_datadir}/kconf_update/kwin-5.23-disable-translucency-effect.sh
%{_datadir}/kconf_update/kwin-5.23-remove-cover-switch.py
%{_datadir}/kconf_update/kwin-5.23-remove-cubeslide.py
%{_datadir}/kconf_update/kwin-5.23-remove-flip-switch.py
%{_datadir}/kconf_update/kwin-5.23-remove-xrender-backend.py
%{_datadir}/kconf_update/kwinrules-5.23-virtual-desktop-ids.py
%{_kf5_datadir}/kservices5/kwin
%{_kf5_datadir}/kservicetypes5/*.desktop
%{_kf5_datadir}/kpackage/kcms/kcm_*
%{_kf5_datadir}/knotifications5/kwin.notifyrc
%{_kf5_datadir}/config.kcfg/kwin.kcfg
%{_kf5_datadir}/config.kcfg/kwindecorationsettings.kcfg
%{_kf5_datadir}/config.kcfg/virtualdesktopssettings.kcfg
%{_kf5_datadir}/config.kcfg/kwin_colorcorrect.kcfg
%{_kf5_datadir}/kconf_update/kwinrules-5.19-placement.pl
%{_kf5_datadir}/kconf_update/kwinrules.upd
%{_kf5_datadir}/kconf_update/kwin-5.25-effect-pluginid-config-group.py
%{_datadir}/icons/hicolor/*/apps/kwin.*
%{_datadir}/knsrcfiles/*.knsrc
%{_datadir}/krunner/dbusplugins/kwin-runner-windows.desktop
%{_datadir}/applications/*.desktop

%files wayland
%{_bindir}/kwin_wayland_wrapper
%{_kf5_bindir}/kwin_wayland
%{_userunitdir}/plasma-kwin_wayland.service

%files x11
%{_kf5_bindir}/kwin_x11
%{_userunitdir}/plasma-kwin_x11.service

%ldconfig_scriptlets libs

%files libs
%{_kf5_datadir}/qlogging-categories5/org_kde_kwin.categories
%{_libdir}/libkwin.so.*
%{_libdir}/libkwineffects.so.*
%{_libdir}/libkwinglutils.so.*
%{_libdir}/libkcmkwincommon.so.*

%files devel
%{_datadir}/dbus-1/interfaces/*.xml
%{_libdir}/cmake/KWinDBusInterface
%{_libdir}/cmake/KWinEffects
%{_libdir}/libkwineffects.so
%{_libdir}/libkwinglutils.so
%{_includedir}/kwin*.h

%files doc -f %{name}-doc.lang
%license LICENSES/*.txt


%changelog
* Mon Dec 26 2022 peijiankang <peijiankang@kylinos.cn> - 5.26.4-1
- update to upstream version 5.26.4

* Mon Sep 05 2022 liweiganga <liweiganga@uniontech.com> - 5.25.4-1
- update to upstream version 5.25.4

* Fri Jul 29 2022 liweiganga <liweiganga@uniontech.com> - 5.25.2-1
- update to upstream version 5.25.2

* Mon Feb 14 2022 peijiankang <peijiankang@kylinos.cn> - 5.24.0-1
- update to upstream version 5.24.0

* Fri Feb 11 2022 peijiankang <peijiankang@kylinos.cn> - 5.23.3-1
- update to upstream version 5.23.3

* Fri Aug 07 2020 weidong <weidong@uniontech.com> - 5.15.4-1
- Initial release for OpenEuler

