~roguescholar/yaknewtab/master

« back to all changes in this revision

Viewing changes to yakuake-session

  • Committer: Jesús Torres
  • Date: 2017-12-29 21:26:34 UTC
  • Revision ID: git-v1:956f154daf7565a77c9779a5fda959395f374453
Refactorization of code when /yakuake/MainWindow_1 is'n available

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
function init_ipc_interface() {
95
95
        local comm=$(detect_ipc_interface)
96
96
        if [[ "$comm" == none ]]; then
 
97
 
97
98
                # Maybe Yakuake is not running. Launch de program and try it again
98
99
                type -P yakuake &> /dev/null ||
99
100
                        error_exit 20 "Yakuake is not installed"
117
118
                        qdbus org.kde.yakuake /yakuake/tabs setTabTitle "$id" "$1"
118
119
                }
119
120
 
120
 
                function yakuake_isvisible_by_dbus() {
121
 
                        qdbus org.kde.yakuake /yakuake/MainWindow_1 Introspect |
122
 
                                grep -F '<interface name="com.trolltech.Qt.QWidget">'
123
 
                        if [[ "$?" == 0 ]]; then
124
 
                                local interface="com.trolltech.Qt.QWidget"
125
 
                        else
126
 
                                local interface="org.qtproject.Qt.QWidget"
127
 
                        fi
128
 
                        echo $(qdbus org.kde.yakuake /yakuake/MainWindow_1 Get "$interface" visible)
129
 
                }
130
 
 
131
 
                function yakuake_isvisible_by_xprop() {
132
 
                        local id=''
133
 
                        local ids=$(xprop -root 32x ':$0+' _NET_CLIENT_LIST_STACKING |
134
 
                          cut -d ':' -f2 | tr ',' ' ')
135
 
                        for id in $ids; do
136
 
                                local wm_class=$(xprop -id $id 8s ':$0+' WM_CLASS | cut -d ':' -f2)
137
 
                                if [[ "${wm_class,,}" == '"yakuake", "yakuake"' ]]; then
138
 
                                        echo true
139
 
                                        return
140
 
                                fi
141
 
                        done
142
 
                        echo false
143
 
                }
144
 
 
145
 
                function yakuake_isvisible() {
146
 
                        qdbus org.kde.yakuake | grep -F '/yakuake/MainWindow_1' > /dev/null
147
 
                        if [[ "$?" == 0 ]]; then
148
 
                                yakuake_isvisible_by_dbus
149
 
                        else
150
 
                                yakuake_isvisible_by_xprop
151
 
                        fi
152
 
                }
153
 
 
154
 
                function yakuake_showwindow() {
155
 
                        local ws=$(yakuake_isvisible)
156
 
                        if [[ "$ws" != true ]]; then
157
 
                                qdbus org.kde.yakuake /yakuake/window toggleWindowState > /dev/null
158
 
                        else
159
 
                                local ids=$(xprop -root 32x ':$0+' _NET_CLIENT_LIST_STACKING | cut -d ':' -f2 | tr ',' ' ')
160
 
                                for id in $ids; do
161
 
                                        local wm_class=$(xprop -id $id 8s ':$0+' WM_CLASS | cut -d ':' -f2)
 
121
                # Check if we can handle the Yakuake main window using DBUS
 
122
                qdbus org.kde.yakuake | grep -F '/yakuake/MainWindow_1' > /dev/null
 
123
                if [[ "$?" == 0 ]]; then
 
124
 
 
125
                        function yakuake_showwindow() {
 
126
                                qdbus org.kde.yakuake /yakuake/MainWindow_1 Introspect |
 
127
                                        grep -F '<interface name="com.trolltech.Qt.QWidget">' > /dev/null
 
128
                                if [[ "$?" == 0 ]]; then
 
129
                                        local interface="com.trolltech.Qt.QWidget"
 
130
                                else
 
131
                                        local interface="org.qtproject.Qt.QWidget"
 
132
                                fi
 
133
                                local ws=$(qdbus org.kde.yakuake /yakuake/MainWindow_1 Get "$interface" visible)
 
134
                                if [[ "$ws" == true ]]; then
 
135
                                        qdbus org.kde.yakuake /yakuake/MainWindow_1 setFocus > /dev/null
 
136
                                else
 
137
                                        qdbus org.kde.yakuake /yakuake/window toggleWindowState > /dev/null
 
138
                                fi
 
139
                        }
 
140
 
 
141
                else
 
142
 
 
143
                        function yakuake_get_window_id() {
 
144
                                local wid=''
 
145
                                local wids=$(xprop -root 32x ':$0+' _NET_CLIENT_LIST_STACKING |
 
146
                                        cut -d ':' -f2 | tr ',' ' ')
 
147
                                for wid in $wids; do
 
148
                                        local wm_class=$(xprop -id $wid 8s ':$0+' WM_CLASS | cut -d ':' -f2)
162
149
                                        if [[ "${wm_class,,}" == '"yakuake", "yakuake"' ]]; then
163
 
                                                wmctrl -i -a $id
164
 
                                                return
 
150
                                                break
165
151
                                        fi
166
152
                                done
167
 
                        fi
168
 
                }
 
153
                                echo $wid
 
154
                        }
 
155
 
 
156
                        function yakuake_showwindow() {
 
157
                                local wid=$(yakuake_get_window_id)
 
158
                                if [[ -z "$wid" ]]; then
 
159
                                        qdbus org.kde.yakuake /yakuake/window toggleWindowState > /dev/null
 
160
                                else
 
161
                                        wmctrl -i -a $wid
 
162
                                fi
 
163
                        }
 
164
                fi
 
165
 
169
166
        elif [[ "$comm" == dcop ]]; then
 
167
 
170
168
                function yakuake_addsession() {
171
169
                        dcop yakuake DCOPInterface slotAddSession > /dev/null
172
170
                }
180
178
                }
181
179
 
182
180
                function yakuake_showwindow() {
183
 
                        ws="$(dcop yakuake yakuake-mainwindow#1 visible)"
 
181
                        ws="$(dcop yakuake 'yakuake-mainwindow#1' visible)"
184
182
                        if [[ "$?" == 0 && "$ws" == false ]]; then
185
183
                                dcop yakuake DCOPInterface slotToggleState > /dev/null
186
184
                        fi
187
185
                }
 
186
 
188
187
        else
189
188
                error_exit 22 "cannot connect to Yakuake"
190
189
        fi