diff --git a/kcmkwin/kwinrules/main.cpp b/kcmkwin/kwinrules/main.cpp index 477a11dad7..65922861e9 100644 --- a/kcmkwin/kwinrules/main.cpp +++ b/kcmkwin/kwinrules/main.cpp @@ -80,7 +80,7 @@ static Rules* findRule( const QValueList< Rules* >& rules, Window wid ) // QCString extrarole = ""; // TODO QCString machine = info.clientMachine().lower(); Rules* best_match = NULL; - int match_quality = 0; // 0 - no, 1 - generic windowrole or title, 2 - exact match + int match_quality = 0; for( QValueList< Rules* >::ConstIterator it = rules.begin(); it != rules.end(); ++it ) @@ -120,7 +120,7 @@ static Rules* findRule( const QValueList< Rules* >& rules, Window wid ) if( bits == 1 ) quality += 2; } - if( generic ) + if( generic ) // ignore generic rules, use only the ones that are for this window continue; if( !rule->matchType( type ) || !rule->matchRole( role ) @@ -133,7 +133,51 @@ static Rules* findRule( const QValueList< Rules* >& rules, Window wid ) match_quality = quality; } } - return best_match; + if( best_match != NULL ) + return best_match; + Rules* ret = new Rules; + ret->description = i18n( "Settings for %1" ).arg( wmclass_class ); + if( type == NET::Unknown ) + ret->types = NET::NormalMask; + else + ret->types = 1 << type; // convert type to its mask + ret->title = title; // set, but make unimportant + ret->titlematch = Rules::UnimportantMatch; +// ret->extrarole = extra; TODO + ret->extrarolematch = Rules::UnimportantMatch; + if( !role.isEmpty() + && role != "unknown" && role != "unnamed" ) // Qt sets this if not specified + { + ret->wmclasscomplete = false; + ret->wmclass = wmclass_class; + ret->wmclassmatch = Rules::ExactMatch; + ret->windowrole = role; + ret->windowrolematch = Rules::ExactMatch; + } + else // no role set + { + if( wmclass_name != wmclass_class ) + { + ret->wmclasscomplete = true; + ret->wmclass = wmclass_name + ' ' + wmclass_class; + ret->wmclassmatch = Rules::ExactMatch; + } + else + { + // This is a window that has no role set, and both components of WM_CLASS + // match (possibly only differing in case), which most likely means either + // the application doesn't give a damn about distinguishing its various + // windows, or it's an app that uses role for that, but this window + // lacks it for some reason. Use non-complete WM_CLASS matching, also + // include window title in the matching, and pray it causes many more positive + // matches than negative matches. + ret->titlematch = Rules::ExactMatch; + ret->wmclasscomplete = false; + ret->wmclass = wmclass_class; + ret->wmclassmatch = Rules::ExactMatch; + } + } + return ret; } static int edit( Window wid ) @@ -143,22 +187,13 @@ static int edit( Window wid ) Rules* orig_rule = findRule( rules, wid ); RulesDialog dlg; // dlg.edit() creates new Rules instance if edited - Rules* edited_rule = dlg.edit( orig_rule, wid ); - if( edited_rule == NULL ) // cancelled - return 0; - if( edited_rule->isEmpty()) + Rules* edited_rule = dlg.edit( orig_rule ); + if( edited_rule == NULL || edited_rule->isEmpty()) { - if( orig_rule == NULL ) - { // new, without any settings + rules.remove( orig_rule ); + delete orig_rule; + if( orig_rule != edited_rule ) delete edited_rule; - return 0; - } - else - { // removed all settings from already existing - rules.remove( orig_rule ); - delete orig_rule; - delete edited_rule; - } } else if( edited_rule != orig_rule ) { diff --git a/kcmkwin/kwinrules/ruleswidget.cpp b/kcmkwin/kwinrules/ruleswidget.cpp index 40e74f1288..3938d8b058 100644 --- a/kcmkwin/kwinrules/ruleswidget.cpp +++ b/kcmkwin/kwinrules/ruleswidget.cpp @@ -492,16 +492,6 @@ void RulesWidget::detectClicked() detect_dlg->detect( 0 ); } -bool RulesWidget::setWindow( WId w ) - { - assert( detect_dlg == NULL ); - detect_dlg_ok = false; - detect_dlg = new DetectDialog; - connect( detect_dlg, SIGNAL( detectionDone( bool )), this, SLOT( detected( bool ))); - detect_dlg->detect( w ); - return detect_dlg_ok; - } - #define GENERIC_PREFILL( var, func, info, uimethod ) \ if( !enable_##var->isChecked()) \ { \ @@ -616,13 +606,10 @@ RulesDialog::RulesDialog( QWidget* parent, const char* name ) setMainWidget( widget ); } -Rules* RulesDialog::edit( Rules* r, WId w ) +Rules* RulesDialog::edit( Rules* r ) { rules = r; widget->setRules( rules ); - if( rules == NULL && w != 0 ) // creating new one, read data from window - if( !widget->setWindow( w )) - return rules; exec(); return rules; } diff --git a/kcmkwin/kwinrules/ruleswidget.h b/kcmkwin/kwinrules/ruleswidget.h index c59eafb08a..215cc84d45 100644 --- a/kcmkwin/kwinrules/ruleswidget.h +++ b/kcmkwin/kwinrules/ruleswidget.h @@ -39,7 +39,6 @@ class RulesWidget void setRules( Rules* r ); Rules* rules() const; bool finalCheck(); - bool setWindow( WId w ); signals: void changed( bool state ); protected slots: @@ -90,7 +89,7 @@ class RulesDialog Q_OBJECT public: RulesDialog( QWidget* parent = NULL, const char* name = NULL ); - Rules* edit( Rules* r, WId w = 0 ); + Rules* edit( Rules* r ); protected: virtual void accept(); private: