src/validators.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2003 - 2004 Anselm R. Garbe <anselmg at t-online.de>
00002 // See ../LICENSE.txt for license details.
00003 //
00004 // $Id: validators.cpp 2 2007-05-16 10:38:27Z eg $
00005 
00006 #include "validators.h"
00007 
00008 #include <map>
00009 
00010 #include "action.h"
00011 #include "client.h"
00012 #include "frame.h"
00013 #include "kernel.h"
00014 #include "inputbar.h"
00015 #include "monitor.h"
00016 #include "slot.h"
00017 #include "statusbar.h"
00018 #include "thing.h"
00019 #include "workspace.h"
00020 
00021 Validators::Validators() {
00022 }
00023 
00024 Validators::~Validators() {
00025 }
00026 
00027 bool Validators::validateSelectClient() {
00028 
00029     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00030 
00031     for (LWorkspace::iterator wit = focusedMonitor->begin();
00032             wit != focusedMonitor->end(); wit++)
00033     {
00034         Workspace *workspace = *wit;
00035  
00036         if (workspace->floatingClients()->size() ||
00037             (workspace->focusedFrame() &&
00038              workspace->focusedFrame()->size()))
00039         {
00040             return true;
00041         }
00042 
00043     }
00044 
00045     return false;
00046 }
00047 
00048 bool Validators::validateCycleFrame() {
00049 
00050     return existFrames() && isFrameFocused();
00051 
00052 }
00053 
00054 bool Validators::validateInputMode() {
00055 
00056     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00057     return !focusedMonitor->inputBar()->isVisible();
00058 }
00059 
00060 
00061 bool Validators::isAlwaysPossible() {
00062 
00063     return true;
00064 }
00065 
00066 bool Validators::isWorkspaceFocused() {
00067 
00068     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00069 
00070     return focusedMonitor->focused() != 0;
00071 }
00072 
00073 bool Validators::existMonitors() {
00074     return KERNEL->monitors()->size() > 1;
00075 }
00076 
00077 bool Validators::existWorkspaces() {
00078 
00079     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00080 
00081     return focusedMonitor->size() > 1;
00082 }
00083 
00084 bool Validators::isEmptyWorkspaceFocused() {
00085 
00086     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00087     Workspace *workspace = focusedMonitor->focused();
00088 
00089     if (workspace->floatingClients()->size() ||
00090             (workspace->focusedFrame() &&
00091              workspace->focusedFrame()->size()))
00092     {
00093         return false;
00094     }
00095     return true;
00096 }
00097 
00098 bool Validators::validateDestroyAction() {
00099 
00100     MBindings *bindings = KERNEL->actionBindings();
00101     for (MBindings::iterator it = bindings->begin();
00102             it != bindings->end(); it++)
00103     {
00104         Action *action = (*it).second;
00105         if (action->type() != Action::INTERN) {
00106             return true;
00107         }
00108     }
00109     return false;
00110 }
00111 
00112 bool Validators::validateDestroyWorkspace() {
00113 
00114     return isEmptyWorkspaceFocused() && existWorkspaces();
00115 }
00116 
00117 bool Validators::existsFrameLeft() {
00118 
00119     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00120     Workspace *workspace = focusedMonitor->focused();
00121 
00122     return workspace->neighborTree(LEFT) != 0;
00123 }
00124 
00125 bool Validators::existsFrameRight() {
00126 
00127     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00128     Workspace *workspace = focusedMonitor->focused();
00129 
00130     return workspace->neighborTree(RIGHT) != 0;
00131 }
00132 
00133 bool Validators::existsFrameUp() {
00134 
00135     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00136     Workspace *workspace = focusedMonitor->focused();
00137 
00138     return workspace->neighborTree(UP) != 0;
00139 }
00140 
00141 bool Validators::existsFrameDown() {
00142 
00143     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00144     Workspace *workspace = focusedMonitor->focused();
00145 
00146     return workspace->neighborTree(DOWN) != 0;
00147 }
00148 
00149 bool Validators::validateToggleMode() {
00150 
00151     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00152     Workspace *workspace = focusedMonitor->focused();
00153 
00154     if (workspace->isFrameMode()) {
00155         return workspace->floatingClients()->size();
00156     }
00157     else {
00158         return workspace->frames()->size();
00159     }
00160 }
00161 
00162 bool Validators::existFrames() {
00163 
00164     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00165     Workspace *workspace = focusedMonitor->focused();
00166 
00167     if (workspace) {
00168         return workspace->frames()->size();
00169     }
00170 
00171     return false;
00172 }
00173 
00174 bool Validators::validateResizeLeft() {
00175 
00176     return isClientFrameFocused() || existsFrameLeft();
00177 }
00178 
00179 bool Validators::validateResizeRight() {
00180 
00181     return isClientFrameFocused() || existsFrameRight();
00182 }
00183 
00184 bool Validators::validateResizeUp() {
00185 
00186     return isClientFrameFocused() || existsFrameUp();
00187 }
00188 
00189 bool Validators::validateResizeDown() {
00190 
00191     return isClientFrameFocused() || existsFrameDown();
00192 }
00193 
00194 bool Validators::isFrameOrClientFrameFocused() {
00195 
00196     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00197     Workspace *workspace = focusedMonitor->focused();
00198 
00199     if (workspace) {
00200         Thing *thing = workspace->focusedThing();
00201 
00202         if (!thing) {
00203             return false;
00204         }
00205 
00206         return thing->hasDecoration();
00207     }
00208     return false;
00209 
00210 }
00211 
00212 
00213 bool Validators::isFrameFocused() {
00214 
00215     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00216     Workspace *workspace = focusedMonitor->focused();
00217 
00218     if (workspace) {
00219         return workspace->focusedFrame() && workspace->isFrameMode();
00220     }
00221     return false;
00222 }
00223 
00224 
00225 bool Validators::isClientFrameFocused() {
00226 
00227     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00228     Workspace *workspace = focusedMonitor->focused();
00229 
00230     if (!workspace) {
00231         return false;
00232     }
00233 
00234     Client *client = workspace->topClient();
00235 
00236     if (!client) {
00237         return false;
00238     }
00239 
00240     return !client->frame();
00241 }
00242 
00243 bool Validators::isFloatingClientFocused() {
00244 
00245     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00246     Workspace *workspace = focusedMonitor->focused();
00247 
00248     if (workspace) {
00249         Thing *thing = workspace->focusedThing();
00250 
00251         if (!thing) {
00252             return false;
00253         }
00254 
00255         return thing->type() != Thing::FRAME;
00256     }
00257 
00258     return false;
00259 }
00260 
00261 bool Validators::isClientFocused() {
00262 
00263     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00264     Workspace *workspace = focusedMonitor->focused();
00265 
00266     return workspace->focusedThing() != 0;
00267 
00268 }
00269 
00270 bool Validators::existClientsWithinFrame() {
00271 
00272     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00273     Workspace *workspace = focusedMonitor->focused();
00274 
00275     if (workspace) {
00276         Thing *thing = workspace->focusedThing();
00277         if (thing && (thing->type() == Thing::FRAME)) {
00278             Frame *frame = (Frame *)thing;
00279             return frame->size() > 1;
00280         }
00281     }
00282 
00283     return false;
00284 }
00285 
00286 bool Validators::existClients() {
00287 
00288     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00289     Workspace *workspace = focusedMonitor->focused();
00290 
00291     if (workspace->isFrameMode()) {
00292         Frame *frame = workspace->focusedFrame();
00293         return frame && (frame->size() > 1);
00294     }
00295     else {
00296         return (workspace->floatingClients()->size() > 1);
00297     }
00298 }
00299 
00300 bool Validators::existDetachedClients() {
00301 
00302     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00303 
00304     return isWorkspaceFocused() &&
00305         (focusedMonitor->detachedClients()->size() > 1);
00306 }
00307 
00308 bool Validators::existsDetachedClient() {
00309 
00310     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00311 
00312     return isWorkspaceFocused() &&
00313         (focusedMonitor->detachedClients()->size() > 0);
00314 }
00315 
00316 bool Validators::validateCancelRecord() {
00317     return KERNEL->isRecording();
00318 }
00319 
00320 bool Validators::validateEndRecord() {
00321     return KERNEL->isRecording() && (KERNEL->recordedActions()->size() > 0);
00322 }
00323 
00324 bool Validators::validateBeginRecord() {
00325     return !KERNEL->isRecording();
00326 }
00327 
00328 #ifdef SLOT_SUPPORT
00329 bool Validators::existsSlotClient() {
00330     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00331     return focusedMonitor->slot()->focused()->focused() != 0;
00332 }
00333 
00334 bool Validators::existSlotTabs() {
00335     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00336     return focusedMonitor->slot()->size() > 0;
00337 }
00338 #endif // SLOT_SUPPORT
00339 
00340 bool Validators::validateHookClient() {
00341 
00342 #ifdef SLOT_SUPPORT
00343     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00344     Slot *slot = focusedMonitor->slot();
00345     Client *client = slot->focused()->focused();
00346     if (client && slot->isGrabFocus()) {
00347         return true;
00348     }
00349 #endif // SLOT_SUPPORT
00350     return isClientFocused();
00351 }
00352 
00353 bool Validators::validateUnhookClient() {
00354 
00355     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00356     Client *client = 0;
00357 #ifdef SLOT_SUPPORT
00358     Slot *slot = focusedMonitor->slot();
00359     client = slot->focused()->focused();
00360     if (client && (client->hooked() == "")
00361         && slot->isGrabFocus())
00362     {
00363         return true;
00364     }
00365 #endif // SLOT_SUPPORT
00366     Workspace *workspace = focusedMonitor->focused();
00367     client = workspace->topClient();
00368     return client && (client->hooked() == "");
00369 }
00370 
00371 bool Validators::validateDestroyFrame() {
00372     Monitor *focusedMonitor = KERNEL->focusedMonitor();
00373     Workspace *workspace = focusedMonitor->focused();
00374     Frame *frame = workspace->focusedFrame();
00375 
00376     return frame && !frame->size();
00377 }

Generated on Thu May 24 15:19:32 2007 for ncwm by  doxygen 1.5.1