File indexing completed on 2024-12-08 13:18:51
0001 /* 0002 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "actions.h" 0008 #include "windows_handler.h" 0009 #include "windows_helper/window_selection_list.h" 0010 0011 #include <KConfigGroup> 0012 #include <KSharedConfig> 0013 #include <QDebug> 0014 0015 namespace KHotKeys 0016 { 0017 ActivateWindowActionVisitor::~ActivateWindowActionVisitor() 0018 { 0019 } 0020 0021 ActivateWindowAction::ActivateWindowAction(ActionData *data_P, const Windowdef_list *window_P) 0022 : Action(data_P) 0023 , _window(window_P) 0024 { 0025 } 0026 0027 void ActivateWindowAction::accept(ActionVisitor &visitor) 0028 { 0029 if (ActivateWindowActionVisitor *v = dynamic_cast<ActivateWindowActionVisitor *>(&visitor)) { 0030 v->visit(*this); 0031 } else { 0032 qDebug() << "Visitor error"; 0033 } 0034 } 0035 0036 const Windowdef_list *ActivateWindowAction::window() const 0037 { 0038 return _window; 0039 } 0040 0041 ActivateWindowAction::~ActivateWindowAction() 0042 { 0043 delete _window; 0044 } 0045 0046 void ActivateWindowAction::cfg_write(KConfigGroup &cfg_P) const 0047 { 0048 base::cfg_write(cfg_P); 0049 cfg_P.writeEntry("Type", "ACTIVATE_WINDOW"); // overwrites value set in base::cfg_write() 0050 KConfigGroup windowGroup(cfg_P.config(), cfg_P.name() + "Window"); 0051 window()->cfg_write(windowGroup); 0052 } 0053 0054 void ActivateWindowAction::execute() 0055 { 0056 if (window()->match(windows_handler->active_window())) 0057 return; // is already active 0058 WId win_id = windows_handler->find_window(window()); 0059 if (win_id != XCB_WINDOW_NONE) 0060 windows_handler->activate_window(win_id); 0061 } 0062 0063 const QString ActivateWindowAction::description() const 0064 { 0065 return i18n("Activate window: ") + window()->comment(); 0066 } 0067 0068 Action *ActivateWindowAction::copy(ActionData *data_P) const 0069 { 0070 return new ActivateWindowAction(data_P, window()->copy()); 0071 } 0072 0073 void ActivateWindowAction::set_window_list(Windowdef_list *list) 0074 { 0075 delete _window; 0076 _window = list; 0077 } 0078 0079 } // namespace KHotKeys