Hello community,

here is the log from the commit of package suse-prime for openSUSE:Factory 
checked in at 2019-03-26 22:33:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/suse-prime (Old)
 and      /work/SRC/openSUSE:Factory/.suse-prime.new.25356 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "suse-prime"

Tue Mar 26 22:33:03 2019 rev:6 rq:688196 version:0.6.5

Changes:
--------
--- /work/SRC/openSUSE:Factory/suse-prime/suse-prime.changes    2019-01-26 
22:25:13.618719348 +0100
+++ /work/SRC/openSUSE:Factory/.suse-prime.new.25356/suse-prime.changes 
2019-03-26 22:33:32.925689475 +0100
@@ -1,0 +2,64 @@
+Sun Mar 24 21:40:17 UTC 2019 - Mykola Krachkovsky <w01dn...@gmail.com>
+
+- Split power support into separate package suse-prime-bbswitch
+  which don't need manual work
+
+-------------------------------------------------------------------
+Tue Mar 19 14:42:56 UTC 2019 - Stefan Dirsch <sndir...@suse.com>
+
+- Update to version 0.6.5
+  * augmented README
+  * do not mention "intel" driver issue with kwin since it is obsolete
+  * improved "intel" xorg config to work properly with compositors
+
+-------------------------------------------------------------------
+Mon Feb 25 11:05:54 UTC 2019 - sndir...@suse.com
+
+- Update to version 0.6.4
+  * added support for xdm and kdm
+  * removed useless "sudo" in journalctl calls
+
+-------------------------------------------------------------------
+Fri Feb 22 09:48:49 UTC 2019 - sndir...@suse.com
+
+- Update to version 0.6.3
+  * Best DM support (lightdm added) 
+
+-------------------------------------------------------------------
+Thu Feb 21 09:54:47 UTC 2019 - sndir...@suse.com
+
+- Update to version 0.6.2
+  - fixes all known issues with GDM, runlevel 3 and manually-started
+    x sessions
+    * Xorg logfile comparision no longer necessary, let's use
+      journalctl to check user logout
+    * other DM(s) than sddm/gdm will be implemented in the future
+
+-------------------------------------------------------------------
+Fri Feb  8 14:40:50 UTC 2019 - sndir...@suse.com
+
+- Update to version 0.6.1
+  * mainly bugfixes
+- supersedes 0001-Resolved-multiple-unexistent-file-error.patch
+
+-------------------------------------------------------------------
+Wed Jan 30 11:56:58 UTC 2019 - sndir...@suse.com
+
+- Update to version 0.6
+  * new systemd service file prime-boot-selector in addition to prime-select
+    + Service prime-select chooses with whatever driver was previously set by 
user.
+    + Service prime-boot-selector sets all things during boot [MUST BE ENABLED]
+  * new prime-select command options
+    + prime-select boot intel|intel2|nvidia|last
+    + prime-select next-boot intel|intel2|nvidia|abort
+    + prime-select service check|disable|restore
+- 0001-Resolved-multiple-unexistent-file-error.patch (post 0.6)
+  * Resolved multiple unexistent file errors
+  * Resolved a big issue in switch command if prime_logfile doesn't exist,
+    file check added
+  * Added non existent file handling in various parts of script (next-boot,
+    log-view, unset, current_check) Those issues manifested themselves
+    after a fresh installation, because some config files still were not
+    present
+
+-------------------------------------------------------------------

Old:
----
  SUSEPrime-0.5.tar.gz

New:
----
  SUSEPrime-0.6.5.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ suse-prime.spec ++++++
--- /var/tmp/diff_new_pack.5ajxJ3/_old  2019-03-26 22:33:33.457689346 +0100
+++ /var/tmp/diff_new_pack.5ajxJ3/_new  2019-03-26 22:33:33.461689345 +0100
@@ -12,12 +12,12 @@
 # license that conforms to the Open Source Definition (Version 1.9)
 # published by the Open Source Initiative.
 
-# Please submit bugfixes or comments via http://bugs.opensuse.org/
+# Please submit bugfixes or comments via https://bugs.opensuse.org/
 #
 
 
 Name:           suse-prime
-Version:        0.5
+Version:        0.6.5
 Release:        0
 Summary:        GPU (nvidia/intel) selection for NVIDIA optimus laptops
 License:        SUSE-Public-Domain
@@ -27,6 +27,7 @@
 Recommends:     nvidia_driver
 Supplements:    modalias(nvidia_driver:pci:v00008086d*sv*sd*bc03sc*i*)
 Conflicts:      suse-prime-alt
+Conflicts:      suse-prime-bbswitch
 BuildArch:      noarch
 
 %description
@@ -34,6 +35,22 @@
 NVIDIA GPU on a Optimus Laptop. The switching is similar to
 the feature provided by the nvidia-prime package in Ubuntu.
 
+%package bbswitch
+Summary:        GPU (nvidia/intel) selection for NVIDIA optimus laptops with 
bbswitch support
+Group:          System/X11/Utilities
+BuildRequires:  systemd
+Requires:       bbswitch
+Conflicts:      suse-prime-alt
+Conflicts:      suse-prime
+BuildArch:      noarch
+%{?systemd_requires}
+
+%description bbswitch
+A collection of shell scripts that makes it possible to use the
+NVIDIA GPU on a Optimus Laptop. The switching is similar to
+the feature provided by the nvidia-prime package in Ubuntu.
+Uses bbswitch to switch on/of power of NVIDIA GPU.
+
 %prep
 %setup -n SUSEPrime-%{version}
 
@@ -45,17 +62,44 @@
 install -m 0644 xorg-intel.conf  %{buildroot}%{_sysconfdir}/prime/
 install -m 0644 xorg-intel-intel.conf  %{buildroot}%{_sysconfdir}/prime/
 install -m 0644 xorg-nvidia.conf %{buildroot}%{_sysconfdir}/prime/
-install -m 0644 09-nvidia-blacklist.conf %{buildroot}%{_sysconfdir}/prime/
-install -m 0644 prime-select.service %{buildroot}%{_sysconfdir}/prime/
+mkdir -p %{buildroot}%{_sysconfdir}/modprobe.d
+install -m 0644 09-nvidia-blacklist.conf %{buildroot}%{_sysconfdir}/modprobe.d/
+mkdir -p %{buildroot}%{_unitdir}
+install -m 0644 prime-select.service %{buildroot}%{_unitdir}/
+install -m 0644 prime-boot-selector.service %{buildroot}%{_unitdir}/
 echo       "undefined"         > %{buildroot}%{_sysconfdir}/prime/current_type
 install -D -m 0755 prime-select.sh %{buildroot}%{_sbindir}/prime-select
 
 %preun
 if [ "$1" -eq 0 ]; then
    # cleanup before uninstalling the package completely
+   export PATH=$PATH:/usr/sbin
    %{_sbindir}/prime-select unset
 fi
 
+%pre bbswitch
+%service_add_pre prime-boot-selector.service
+
+%post bbswitch
+%{?regenerate_initrd_post}
+%service_add_post prime-boot-selector.service
+systemctl enable prime-boot-selector.service
+
+%preun bbswitch
+%service_del_preun prime-boot-selector.service
+if [ "$1" -eq 0 ]; then
+   # cleanup before uninstalling the package completely
+   export PATH=$PATH:/usr/sbin
+   %{_sbindir}/prime-select unset
+fi
+
+%postun bbswitch
+%{?regenerate_initrd_post}
+%service_del_postun prime-boot-selector.service
+
+%posttrans bbswitch
+%{?regenerate_initrd_posttrans}
+
 %files
 %defattr(-,root,root)
 %doc README.md
@@ -63,9 +107,19 @@
 %config %{_sysconfdir}/prime/xorg-intel.conf
 %config %{_sysconfdir}/prime/xorg-intel-intel.conf
 %config %{_sysconfdir}/prime/xorg-nvidia.conf
-%config %{_sysconfdir}/prime/09-nvidia-blacklist.conf
-%config %{_sysconfdir}/prime/prime-select.service
 %config(noreplace) %{_sysconfdir}/prime/current_type
 %{_sbindir}/prime-select
 
+%files bbswitch
+%doc README.md
+%{_sysconfdir}/prime
+%config %{_sysconfdir}/prime/xorg-intel.conf
+%config %{_sysconfdir}/prime/xorg-intel-intel.conf
+%config %{_sysconfdir}/prime/xorg-nvidia.conf
+%config(noreplace) %{_sysconfdir}/prime/current_type
+%{_sbindir}/prime-select
+%config %{_sysconfdir}/modprobe.d/09-nvidia-blacklist.conf
+%{_unitdir}/prime-select.service
+%{_unitdir}/prime-boot-selector.service
+
 %changelog

++++++ SUSEPrime-0.5.tar.gz -> SUSEPrime-0.6.5.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SUSEPrime-0.5/README.md new/SUSEPrime-0.6.5/README.md
--- old/SUSEPrime-0.5/README.md 2019-01-24 21:08:13.000000000 +0100
+++ new/SUSEPrime-0.6.5/README.md       2019-03-19 15:38:44.000000000 +0100
@@ -1,10 +1,10 @@
-OpenSUSE nvidia-prime like package
+openSUSE nvidia-prime like package
 ==================================
 
 Assumptions
 -----------
 
-* You are running OpenSUSE Tumbleweed
+* You are running openSUSE Tumbleweed
 * You don't have bumblebee installed
 * You installed nvidia drivers using http://opensuse-community.org/nvidia.ymp
 
@@ -24,6 +24,10 @@
 * Bo Simonsen <b...@geekworld.dk>
 * Michal Srb <m...@suse.com>
 
+Related projects
+----------------
+
+* SUSEPrimeQT <https://github.com/simopil/SUSEPrimeQt/> Provides a simple GUI 
for SUSEPrime
 
 NVIDIA power off support
 -------------------------
@@ -53,61 +57,47 @@
 
 This will also blacklist the `nouveau` module which can really get in the way 
with Optimus and causing black screens.
 
-### Install the systemd service for loading NVIDIA module when needed
+### Install the systemd services for doing switch and set correct card during 
boot
 
 ```
-cp /etc/prime/prime-select.service /usr/lib/systemd/system
-systemctl enable prime-select
+cp /etc/prime/prime-select.service           /usr/lib/systemd/system
+cp /etc/prime/prime-boot-selector.service    /usr/lib/systemd/system
+systemctl enable prime-boot-selector
 ```
 
-This service calls prime-select with whatever driver was previously set by 
user.
-If nvidia is set, it will load the NVIDIA modules before starting the Display 
Manager (login screen).
+Service prime-select chooses with whatever driver was previously set by user.
+Service prime-boot-selector sets all things during boot [MUST BE ENABLED]
+If nvidia is set, it will load the NVIDIA modules before starting the 
Graphical Target.
 Moreover, if an intel config is set but the Intel card was disabled in BIOS 
(leaving only the dGPU), this service will automatically switch to the nvidia 
config.
 
 
 ## FAQ
 
-### What are the script parameters to select a driver ?
+### How do I select a driver ?
 
 prime-select `<driver>`
 
-Where `driver` is one of:
+Where `<driver>` is one of:
 
-- `intel`: uses the modesetting driver
-- `intel2`: uses the intel driver (xf86-video-intel). If you use Plasma you 
might get corrupted flickering display. To fix this make sure to disable vsync 
in the Plasma compositor settings first. Vsync will be handled by the intel 
driver
+- `intel`: use the `modesetting` driver
+- `intel2`: use the `intel` driver (xf86-video-intel)
 - `nvidia`: use the NVIDIA binary driver
 
 
-### How do I switch from nvidia to intel with NVIDIA power off support ?
-
-
-It requires switching runlevels for the script to be able to remove the NVIDIA 
modules and power off the card:
-
-Exit Xorg, going into runlevel 3 (multi-user):
-
-```
-<save all your work in Xorg, close programs as needed>
-sudo init 3
-<login as root on console>
-```
-
-Use the script to change driver:
-
-```
-prime-select intel
-```
-
-Restart in run level 5 (graphical mode) with the new driver:
+### How do I check the current driver configured and the power state of the 
NVIDIA card ?
 
 ```
-init 5
+/usr/sbin/prime-select get-current
+Driver configured: intel
+[bbswitch] NVIDIA card is OFF
 ```
 
-### How to I check that the NVIDIA card is powered off ?
+To get more details on the Xorg driver, install package `inxi` if necessary 
and use `inxi -G`:
 
 ```
-cat /proc/acpi/bbswitch 
-0000:01:00.0 OFF
+inxi -G
+Graphics:  Device-1: Intel UHD Graphics 630 driver: i915 v: kernel 
+           Device-2: NVIDIA GP107GLM [Quadro P600 Mobile] driver: N/A 
+           Display: x11 server: X.Org 1.20.4 driver: intel resolution: 
3840x2160~60Hz 
+           OpenGL: renderer: Mesa DRI Intel UHD Graphics 630 (Coffeelake 3x8 
GT2) v: 4.5 Mesa 18.3.4
 ```
-
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SUSEPrime-0.5/prime-boot-selector.service 
new/SUSEPrime-0.6.5/prime-boot-selector.service
--- old/SUSEPrime-0.5/prime-boot-selector.service       1970-01-01 
01:00:00.000000000 +0100
+++ new/SUSEPrime-0.6.5/prime-boot-selector.service     2019-03-19 
15:38:44.000000000 +0100
@@ -0,0 +1,11 @@
+[Unit]
+Description=Prime Select Service (Boot Selector)
+After=multi-user.target
+Before=display-manager.service
+
+[Service]
+Type=oneshot
+ExecStart=prime-select prime_booting
+
+[Install]
+WantedBy=multi-user.target
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SUSEPrime-0.5/prime-select.service 
new/SUSEPrime-0.6.5/prime-select.service
--- old/SUSEPrime-0.5/prime-select.service      2019-01-24 21:08:13.000000000 
+0100
+++ new/SUSEPrime-0.6.5/prime-select.service    2019-03-19 15:38:44.000000000 
+0100
@@ -1,5 +1,6 @@
 [Unit]
 Description=Prime Select Service
+After=multi-user.target
 Before=display-manager.service
 
 [Service]
@@ -7,4 +8,4 @@
 ExecStart=prime-select apply-current
 
 [Install]
-WantedBy=graphical.target
+WantedBy=multi-user.target
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SUSEPrime-0.5/prime-select.sh 
new/SUSEPrime-0.6.5/prime-select.sh
--- old/SUSEPrime-0.5/prime-select.sh   2019-01-24 21:08:13.000000000 +0100
+++ new/SUSEPrime-0.6.5/prime-select.sh 2019-03-19 15:38:44.000000000 +0100
@@ -7,28 +7,51 @@
 # Adapted for OpenSUSE Tumbleweed by Michal Srb <m...@suse.com>
 # Extended for TUXEDO Computers by Vinzenz Vietzke <v...@tuxedocomputers.com>
 # Augmented by bubbleguuum <bubblegu...@free.fr>
+# Improved by simopil <pilia.simon...@gmail.com>
 
 type=$1
 xorg_nvidia_conf="/etc/prime/xorg-nvidia.conf"
 xorg_intel_conf_intel="/etc/prime/xorg-intel.conf"
 xorg_intel_conf_intel2="/etc/prime/xorg-intel-intel.conf"
+prime_logfile="/var/log/prime-select.log"
 nvidia_modules="nvidia_drm nvidia_modeset nvidia_uvm nvidia"
 driver_choices="nvidia|intel|intel2"
 lspci_intel_line="VGA compatible controller: Intel"
 
 function usage {
     echo
-    echo "usage: `basename $0` $driver_choices|unset|get-current|apply-current"
+    echo "usage: `basename $0`           
$driver_choices|unset|get-current|get-boot|log-view|log-clean"
+    echo "usage: `basename $0` boot      $driver_choices|last"
+    echo "usage: `basename $0` next-boot $driver_choices|abort"
+    echo "usage: `basename $0` service   check|disable|restore"
     echo
-    echo "intel: use the Intel card with the modesetting driver"
-    echo "intel2: use the Intel card with the Intel open-source driver 
(xf86-video-intel). If you use this driver in a Plasma session, make sure to 
first disable vsync in the Plasma compositor settings to prevent video 
corruption"
-    echo "nvidia: use the NVIDIA binary driver"
-    echo "unset: disable effects of this script and let Xorg decide what 
driver to use"
+    echo "intel:       use the Intel card with the \"modesetting\" driver"
+    echo "intel2:      use the Intel card with the \"intel\" Open Source 
driver (xf86-video-intel)"
+    echo "nvidia:      use the NVIDIA proprietary driver"
+    echo "boot:        select default card at boot or set last used"
+    echo "next-boot:   select card ONLY for next boot, it not touches your 
boot preference. abort: restores next boot to default"
+    echo "get-boot:    display default card at boot"
+    echo "service:     disable, check or restore prime-select service. Could 
be useful disabling service"
+    echo "             before isolating multi-user.target to prevent service 
execution."
+    echo "log-view:    view switching logfile to see errors or debug"
+    echo "log-clean:   clean logfile"
+    echo "unset:       disable effects of this script and let Xorg decide what 
driver to use"
     echo "get-current: display driver currently in use by this tool"
-    echo "apply-current: re-apply this script using previously set driver 
(used by prime-select systemd service)"
+    echo
+    echo "##FOLLOWING COMMANDS ARE USED BY prime-select SERVICEs, DON'T USE 
THEM MANUALLY##"
+    echo "apply-current:      re-apply this script using previously set driver 
(used by prime-select systemd service)"
+    echo "user_logout_waiter: waits user logout (used by prime-select systemd 
service)"
+    echo "prime_booting:      sets correct card during boot (used by 
prime-boot-selector systemd service)"
     echo
 }
 
+function logging {
+    if ! [ -f $prime_logfile ]; then 
+        echo "##SUSEPrime logfile##" > $prime_logfile
+    fi
+    echo "[ $(date +"%H:%M:%S") ] ${1}" >> $prime_logfile
+}
+
 function check_root {
     if (( $EUID != 0 )); then
         echo "You must run this script as root"
@@ -36,96 +59,86 @@
     fi
 }
 
+function bbcheck {
+    if [ "$(rpm -q bbswitch | grep bbswitch-)" > /dev/null ]; then
+        if [ "$(grep OFF /proc/acpi/bbswitch)" > /dev/null ]; then
+            echo "[bbswitch] NVIDIA card is OFF"
+        elif [ "$(grep ON /proc/acpi/bbswitch)" > /dev/null ]; then
+            echo "[bbswitch] NVIDIA card is ON"
+        else
+            echo "bbswitch is installed but seems broken. Cannot change nvidia 
power status"
+        fi
+    else
+        echo "bbswitch is not installed. NVIDIA card will not be powered off"
+    fi
+}
+
 function clean_files {
     rm -f /etc/X11/xorg.conf.d/90-nvidia.conf
     rm -f /etc/X11/xorg.conf.d/90-intel.conf
 }
 
-case $type in
-    
-    apply-current)
-       
-        if [ -f /etc/prime/current_type ]; then
-            
-            current_type=`cat /etc/prime/current_type`
-            
-            if [ "$current_type" != "nvidia"  ] && ! lspci | grep 
"$lspci_intel_line" > /dev/null; then
-                
-                # this can happen if user set intel but changed to "Discrete 
only" in BIOS
-                # in that case the Intel card is not visible to the system and 
we must switch to nvidia
-                
-                echo "Forcing nvidia due to Intel card not found"
-                current_type="nvidia"
-            fi
-            
-            $0 $current_type
-        fi
-        ;;
-    
-    nvidia)
-
-       check_root
-       
-       if [ -f /proc/acpi/bbswitch ]; then        
-            tee /proc/acpi/bbswitch > /dev/null <<EOF
+function set_nvidia {
+    if [ -f /proc/acpi/bbswitch ]; then        
+        tee /proc/acpi/bbswitch > /dev/null <<EOF
 ON
 EOF
-       fi
-
-       # will load all other dependency modules
-       modprobe nvidia_drm
-        
-       gpu_info=`nvidia-xconfig --query-gpu-info`
-       # This may easily fail, if no NVIDIA kernel module is available or alike
-       if [ $? -ne 0 ]; then
-            echo "PCI BusID of NVIDIA card could not be detected!"
-            exit 1
-       fi
+    fi
+    
+    logging "trying switch ON nvidia: $(bbcheck)"
+    # will load all other dependency modules
+    modprobe nvidia_drm
+    
+    gpu_info=`nvidia-xconfig --query-gpu-info`
+        # This may easily fail, if no NVIDIA kernel module is available or 
alike
+    if [ $? -ne 0 ]; then
+        logging "PCI BusID of NVIDIA card could not be detected!"
+        exit 1
+    fi
        
-       # There could be more than on NVIDIA card/GPU; use the first one in 
that case
+    # There could be more than on NVIDIA card/GPU; use the first one in that 
case
 
-       nvidia_busid=`echo "$gpu_info" |grep -i "PCI BusID"|head -n 1|sed 
's/PCI BusID ://'|sed 's/ //g'`
+    nvidia_busid=`echo "$gpu_info" |grep -i "PCI BusID"|head -n 1|sed 's/PCI 
BusID ://'|sed 's/ //g'`
 
-       libglx_nvidia=`update-alternatives --list libglx.so|grep 
nvidia-libglx.so`
+    libglx_nvidia=`update-alternatives --list libglx.so|grep nvidia-libglx.so`
 
-       update-alternatives --set libglx.so $libglx_nvidia > /dev/null
+    update-alternatives --set libglx.so $libglx_nvidia > /dev/null
 
-       clean_files
+    clean_files
 
-       cat $xorg_nvidia_conf | sed 's/PCI:X:X:X/'${nvidia_busid}'/' > 
/etc/X11/xorg.conf.d/90-nvidia.conf
+    cat $xorg_nvidia_conf | sed 's/PCI:X:X:X/'${nvidia_busid}'/' > 
/etc/X11/xorg.conf.d/90-nvidia.conf
 
-       echo "$type" > /etc/prime/current_type     
+    echo "nvidia" > /etc/prime/current_type
+    logging "Nvidia card correctly set"
+}
 
-       $0 get-current
-       ;;
+function set_intel {
+    # modesetting driver is part of xorg-x11-server and always available
+    conf=$xorg_intel_conf_intel
+    echo "intel" > /etc/prime/current_type
+    #jump to common function intel1/intel2
+    common_set_intel
+}
     
-    intel|intel2)
-
-       check_root
-       
-       if [ "$type" = "intel2" ]; then
-            if ! rpm -q xf86-video-intel > /dev/null; then
-               echo "package xf86-video-intel is not installed";
-               exit 1
-            fi
-            
-            conf=$xorg_intel_conf_intel2
-       else
-            # modesetting driver is part of xorg-x11-server and always 
available
-            conf=$xorg_intel_conf_intel
-       fi
+function set_intel2 {
+    conf=$xorg_intel_conf_intel2
+    echo "intel2" > /etc/prime/current_type
+    #jump to common function intel1/intel2
+    common_set_intel
+}
 
-       # find Intel card bus id. Without this Xorg may fail to start
+function common_set_intel {
+    # find Intel card bus id. Without this Xorg may fail to start
        line=`lspci | grep "$lspci_intel_line" | head -1`
        if [ $? -ne 0 ]; then
-            echo "Failed to find Intel card with lspci"
-            exit 1
+        logging "Failed to find Intel card with lspci"
+        exit 1
        fi
 
        intel_busid=`echo $line | cut -f 1 -d ' ' | sed -e 's/\./:/g;s/:/ /g' | 
awk -Wposix '{printf("PCI:%d:%d:%d\n","0x" $1, "0x" $2, "0x" $3 )}'`
        if [ $? -ne 0 ]; then
-            echo "Failed to build Intel card bus id"
-            exit 1
+        logging "Failed to build Intel card bus id"
+        exit 1
        fi
        
        libglx_xorg=`update-alternatives --list libglx.so|grep xorg-libglx.so`
@@ -139,40 +152,395 @@
        modprobe -r $nvidia_modules
 
        if [ -f /proc/acpi/bbswitch ]; then        
-            tee /proc/acpi/bbswitch > /dev/null <<EOF 
+        tee /proc/acpi/bbswitch > /dev/null <<EOF 
 OFF
 EOF
-            grep OFF /proc/acpi/bbswitch > /dev/null || echo "Failed to power 
off NVIDIA card"
-
-       else
-            rpm -q bbswitch > /dev/null || echo "bbswitch is not installed. 
NVIDIA card will not be powered off"
-       fi
+    fi
        
-       echo "$type" > /etc/prime/current_type
+       logging "trying switch OFF nvidia: $(bbcheck)"
+       logging "Intel card correctly set"
+}
+
+function apply_current {
+    if [ -f /etc/prime/current_type ]; then
+            
+        current_type=`cat /etc/prime/current_type`
+            
+        if [ "$current_type" != "nvidia"  ] && ! lspci | grep 
"$lspci_intel_line" > /dev/null; then
+                
+            # this can happen if user set intel but changed to "Discrete only" 
in BIOS
+            # in that case the Intel card is not visible to the system and we 
must switch to nvidia
+                
+            logging "Forcing nvidia due to Intel card not found"
+            current_type="nvidia"
+        fi
+            
+        set_$current_type
+            
+        if [ "$(cat /etc/prime/boot_state)" = "S" ]; then
+            echo "N" > /etc/prime/boot_state
+            logging "Reenabling prime-boot-selector [ boot_state > N ]"
+            systemctl disable prime-select
+            systemctl enable prime-boot-selector
+            logging "Reaching graphical.target"
+            systemctl isolate graphical.target
+        fi
+    fi
+}
+
+function current_check {
+    if [ "$(pgrep -fl "prime-select user_logout_waiter")" > /dev/null ]; then
+        echo "Error: a switch operation already in execution"
+        echo "You can undo it using sudo killall prime-select"
+        exit 1
+    fi
+    if ! [ -f /etc/prime/current_type ]; then
+        echo "Preparing first configuration"
+    elif [ "$type" = "$(cat /etc/prime/current_type)" ]; then
+        echo "$type driver already in use!"
+        exit 1
+    fi
+}
 
-       $0 get-current
+case $type in
+    
+    apply-current)
+    
+        check_root
+           apply_current
+    ;;
+    
+    nvidia|intel|intel2)
+    
+        current_check
+        check_root
+        if ! [ -f /var/log/prime-select.log ]; then
+            echo "##SUSEPrime logfile##" > $prime_logfile
+        fi
+        if [ $(wc -l < $prime_logfile) -gt 1000 ]; then
+            #cleaning logfile if has more than 1k events
+            rm $prime_logfile &> /dev/null
+            echo "##SUSEPrime logfile##" > $prime_logfile
+        fi
+        if [ "$type" = "intel2" ];then
+            if ! rpm -q xf86-video-intel > /dev/null; then
+                echo "package xf86-video-intel is not installed";
+                exit 1
+            fi
+        fi
+        if ! [ -f 
/etc/systemd/system/multi-user.target.wants/prime-boot-selector.service ]; then
+            echo "ERROR: prime-select service seems broken or disabled by 
user. Try prime-select service restore"
+            exit 1
+        fi
+        if ! { [ "$(bbcheck)" = "[bbswitch] NVIDIA card is ON" ] || [ 
"$(bbcheck)" = "[bbswitch] NVIDIA card is OFF" ]; }; then
+            bbcheck
+        fi
+        #DM_check
+        runlev=$(runlevel | awk '{print $2}')
+        if [ $runlev = 5 ]; then
+            #GDM_mode
+            if [ "$(systemctl status display-manager | grep gdm)" > /dev/null 
]; then
+                $0 user_logout_waiter $type gdm &
+                logging "user_logout_waiter: started"
+            #SDDM_mode
+            elif [ "$(systemctl status display-manager | grep sddm)" > 
/dev/null ]; then
+                $0 user_logout_waiter $type sddm &
+                logging "user_logout_waiter: started"
+            #lightdm_mode
+            elif [ "$(systemctl status display-manager | grep lightdm)" > 
/dev/null ]; then
+                $0 user_logout_waiter $type lightdm &
+                logging "user_logout_waiter: started"
+            #XDM_mode
+            elif [ "$(systemctl status display-manager | grep xdm)" > 
/dev/null ]; then
+                $0 user_logout_waiter $type xdm &
+                logging "user_logout_waiter: started"
+            #KDM_mode(uses xdm->calls xdm_mode)
+            elif [ "$(systemctl status display-manager | grep kdm)" > 
/dev/null ]; then
+                $0 user_logout_waiter $type xdm &
+                logging "user_logout_waiter: started"
+            #unsupported_dm_force_close_option
+            else
+                echo "Unsupported display-manager, please report this to 
project page to add support."
+                echo "Script works ever in init 3"
+                echo "You can force-close session and switch graphics [could 
be dangerous],"
+                read -p "ALL UNSAVED DATA IN SESSION WILL BE LOST, CONTINUE? 
[Y/N]: " choice 
+                case "$choice" in
+                    y|Y ) 
+                        killall xinit 
+                        $0 user_logout_waiter $type now
+                        ;;
+                    * ) echo "Aborted. Exit."; exit ;;
+                esac
+            fi    
+        #manually_started_X_case
+        elif [ $runlev = 3 ] && [ "$(pgrep -fl "xinit")" > /dev/null ]; then
+            $0 user_logout_waiter $type x_only &
+            logging "user_logout_waiter: started"
+        else
+            echo "Seems you are on runlevel 3."
+            read -p "Do you want to switch graphics now and reach 
graphical.target? [y/n]: " choice
+            case "$choice" in
+                y|Y ) $0 user_logout_waiter $type now ;;
+                * ) echo "Aborted. Exit."; exit ;;
+            esac
+        fi
+        
+           echo -e "Logout to switch graphics"
        ;;
     
+    boot)
+    
+        check_root
+       
+           case $2 in
+           
+            nvidia|intel|intel2|last)
+            
+                if [ "$2" = "intel2" ]; then  
+                    if ! rpm -q xf86-video-intel > /dev/null; then
+                        echo "package xf86-video-intel is not installed";
+                        exit 1
+                    fi
+                fi
+                   echo "$2" > /etc/prime/boot
+                $0 get-boot
+               ;;
+           
+               *)
+           
+                echo "Invalid choice"
+                usage
+               ;;
+        esac
+    ;;
+       
+    next-boot)
+    
+        check_root
+       
+        case $2 in
+          
+            nvidia|intel|intel2)
+                
+                if [ "$2" = "intel2" ]; then  
+                    if ! rpm -q xf86-video-intel > /dev/null; then
+                        echo "package xf86-video-intel is not installed";
+                        exit 1
+                    fi
+                fi
+                echo "$2" > /etc/prime/forced_boot
+                $0 get-boot
+               ;;
+               
+               abort)
+               
+                if [ -f /etc/prime/forced_boot ]; then
+                    rm /etc/prime/forced_boot
+                    echo "Next boot forcing aborted"
+                else
+                    echo "Next boot is NOT forced"
+                    exit 1
+                fi
+               ;;
+
+            *)
+           
+                echo "Invalid choice"
+                usage
+               ;;
+        esac
+    ;;
+       
+       
     get-current)
        
-       if [ -f /etc/prime/current_type ]; then
+           if [ -f /etc/prime/current_type ]; then
             echo -n "Driver configured: "
             cat /etc/prime/current_type
        else
             echo "No driver configured."
             usage
-       fi
-       ;;
+           fi
+        bbcheck
+       ;; 
 
     unset)
 
-       check_root
+           check_root
+           $0 service disable
+           clean_files
+           rm /etc/prime/current_type &> /dev/null
+           rm /etc/prime/boot_state &> /dev/null
+           rm /etc/prime/boot &> /dev/null
+           rm /etc/prime/forced_boot &> /dev/null
+           rm $prime_logfile &> /dev/null
+       ;;
        
-       clean_files
-       rm /etc/prime/current_type
+    service)
+    
+        case $2 in
+        
+            check)
+            
+                if [ -f 
/etc/systemd/system/multi-user.target.wants/prime-boot-selector.service ]; then
+                    if ! [ -f 
/etc/systemd/system/multi-user.target.wants/prime-select.service ]; then
+                        echo "prime-select: service is set correctly"
+                        exit
+                    fi
+                fi
+                echo "prime-select: service has a wrong setting or is disabled 
by user, please do prime-select service restore"
+                echo "If you are running this command in multi-user.target 
please ignore this message"
+            ;;
+            
+            restore)
+            
+                check_root
+                systemctl enable prime-boot-selector
+                systemctl disable prime-select
+                echo "prime-select: service restored"
+                logging "service restored by user"
+            ;;
+            
+            disable)
+                
+                check_root
+                systemctl disable prime-boot-selector
+                systemctl disable prime-select
+                echo -e "prime-select: service disabled. Remember prime-select 
needs this service to work correctly.\nUse prime-select service restore to 
enable service again "
+                logging "service disabled by user"
+            ;;
+            
+            *)
+           
+                echo "Invalid choice"
+                usage
+               ;;
+        esac
+    
        ;;
 
+       user_logout_waiter)
+        
+        currtime=$(date +"%T");
+        #manage journalctl to check when X restarted, then jump init 3
+        case "$3" in
+            
+        gdm )
+            #GDM_mode
+            until [ "$(journalctl --since "$currtime" | grep 
"pam_unix(gdm-password:session): session closed")" > /dev/null ]; do
+                sleep 0.5s
+            done
+            logging "user_logout_waiter: X restart detected, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+        ;;    
+        
+            #SDDM_mode
+        sddm )
+            until [ "$(journalctl --since "$currtime" -e _COMM=sddm | grep 
"Removing display")" > /dev/null ]; do
+                sleep 0.5s
+            done
+            logging "user_logout_waiter: X restart detected, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+        ;;
+        
+            #lightdm_mode
+        lightdm  )
+            until [ "$(journalctl --since "$currtime" -e | grep 
"pam_unix(lightdm:session): session closed")" > /dev/null ]; do
+                sleep 0.5s
+            done
+            logging "user_logout_waiter: X restart detected, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+        ;;
+        
+            #xdm/kdm_mode
+        xdm )
+            until [ "$(journalctl --since "$currtime" -e | grep 
"pam_unix(xdm:session): session closed for user")" > /dev/null ]; do
+                sleep 0.5s
+            done
+            logging "user_logout_waiter: X restart detected, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+            #stopping display-manager before runlev.3 seems work faster
+            systemctl stop display-manager
+        ;;
+        
+            #manually_started_X_case
+        x_only )
+            while [ "$(pgrep -fl "xinit")" > /dev/null ]; do
+                sleep 0.5s
+            done
+            logging "user_logout_waiter: X stop detected, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+        ;;
+        now )
+            logging "user_logout_waiter: runlevel 3 mode, disabling 
prime-boot-selector and preparing switch to $2 [ boot_state > S ]"
+        ;;
+        esac
+        
+        echo $2 > /etc/prime/current_type
+        echo "S" > /etc/prime/boot_state
+        systemctl enable prime-select
+        systemctl disable prime-boot-selector
+        logging "Reaching multi-user.target"
+        systemctl isolate multi-user.target
+       ;;
+       
+       prime_booting)
+       
+        #called by prime-boot-selector service
+        if ! [ -f /etc/prime/boot_state ]; then
+            echo "B" > /etc/prime/boot_state
+        fi
+        if ! [ -f /etc/prime/boot ]; then
+            echo "last" > /etc/prime/boot
+        fi
+        if [ "$(cat /etc/prime/boot_state)" = "N" ]; then
+            logging "prime-boot-selector: useless call caused by isolating 
graphical.target [ boot_state > B ]"
+            echo "B" > /etc/prime/boot_state
+        elif [ -f /etc/prime/forced_boot ]; then
+            echo "$(cat /etc/prime/forced_boot)" > /etc/prime/current_type
+            rm /etc/prime/forced_boot
+            logging "prime-boot-selector: forcing booting with $(cat 
/etc/prime/current_type), boot preference ignored"
+            logging "prime-boot-selector: setting-up $(cat 
/etc/prime/current_type) card"
+            apply_current
+        else
+            boot_type=`cat /etc/prime/boot`
+               if [ "$boot_type" != "last" ]; then
+                echo "$boot_type" > /etc/prime/current_type
+            fi
+            logging "prime-boot-selector: setting-up $(cat 
/etc/prime/current_type) card"
+            apply_current
+        fi
+       ;;
+       
+       get-boot)
+       
+        if [ -f /etc/prime/boot ]; then
+            echo "Default at system boot: $(cat /etc/prime/boot)"
+        else
+            echo "Default at system boot: auto (last)"
+            echo "You can configure it with prime-select boot 
intel|intel2|nvidia|last"
+        fi
+        if [ -f /etc/prime/forced_boot ]; then
+            echo "Next boot forced to $(cat /etc/prime/forced_boot) by user"
+        fi
+       ;;
+       
+       log-view)
+       
+        if [ -f $prime_logfile ]; then
+            less +G -e $prime_logfile
+        else
+            echo "No logfile in /var/log/prime-select.log"
+        fi
+       ;;
+       
+       log-clean)
+       
+        if [ -f $prime_logfile ]; then
+            check_root
+               rm $prime_logfile
+               echo "$prime_logfile removed!"
+           else
+               echo "$prime_logfile is already clean!"
+        fi
+    ;;
+       
     *)
-       usage
+        usage
        ;;
 esac
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/SUSEPrime-0.5/xorg-intel-intel.conf 
new/SUSEPrime-0.6.5/xorg-intel-intel.conf
--- old/SUSEPrime-0.5/xorg-intel-intel.conf     2019-01-24 21:08:13.000000000 
+0100
+++ new/SUSEPrime-0.6.5/xorg-intel-intel.conf   2019-03-19 15:38:44.000000000 
+0100
@@ -6,6 +6,20 @@
 Section "Device"
     Identifier "intel"
     Driver "intel"
+
+    # DRI3 is necessary, otherwise DRI2 is used by default
+    # and this causes issues with compositors (scrolling stutter in
+    # particular)      
+
+    Option "DRI" "3"
+
+    # Unlike what man "intel" says, TearFree is enabled by default
+    # It is unecessary to have it enabled (consumes memory, see man) when a 
competent compositor with
+    # vsync enabled is used. 
+    # Comment this line (or set to "true") if not using a compositor (not 
recommended)
+               
+    Option "TearFree" "false"  
+
     BusID "PCI:X:X:X"
 EndSection
 


Reply via email to