<table><tr><td style="">alexeymin added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D22418">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>not convinced that removing the ifdef is the solution</p></blockquote>

<p>It is, because now availability and presence of command-line options is decided at KWin <strong>compile</strong> time, and it should be decided at <strong>run</strong> time based on the actual list of available plugins. Just removing <tt style="background: #ebebeb; font-size: 13px;">#ifdefs</tt> already solves the problem that I cannot pass <tt style="background: #ebebeb; font-size: 13px;">--hwcomposer</tt> argument to <tt style="background: #ebebeb; font-size: 13px;">kwin_wayland</tt> if KWin was built without libhybris support and hwcomposer plugin is installed later and it can be loaded perfectly (and works fine). That's why we'll have to remove <tt style="background: #ebebeb; font-size: 13px;">#ifdef</tt>s anyway.</p>

<p>I wanted to go with the minimalistic and non-invasive approach, with as little bloodshed as possible. But if you wish to see some rewrites, how about this:</p>

<ul class="remarkup-list">
<li class="remarkup-list-item">Each plugin has a method to help in autodetection process (<tt style="background: #ebebeb; font-size: 13px;">canLoad()</tt>) that quickly checks if the environment conditions are correct and allow loading of this plugin. Previously there was a function <tt style="background: #ebebeb; font-size: 13px;">automaticBackendSelection()</tt>, that did that by just checking <tt style="background: #ebebeb; font-size: 13px;">qEnvironmentVariableIsSet</tt> and so; now each plugin can do more complicated tests than just env vars checking.</li>
<li class="remarkup-list-item">Each plugin has a concept of "priority" for automatic loading, because we need some order among them. This was previously also in <tt style="background: #ebebeb; font-size: 13px;">automaticBackendSelection()</tt>, the order of <tt style="background: #ebebeb; font-size: 13px;">if</tt> statements. The priority is saved in JSON metadata, the same way as the <tt style="background: #ebebeb; font-size: 13px;">"input"</tt> property is now stored and tested in <tt style="background: #ebebeb; font-size: 13px;">Application::initPlatform() </tt>: <a href="https://cgit.kde.org/kwin.git/tree/main.cpp?h=Plasma/5.17#n442" class="remarkup-link" target="_blank" rel="noreferrer">https://cgit.kde.org/kwin.git/tree/main.cpp?h=Plasma/5.17#n442</a></li>
</ul>

<p>It is not trivial to move CLI args providing and parsing into plugins, because some common arguments like <tt style="background: #ebebeb; font-size: 13px;">--width</tt> and <tt style="background: #ebebeb; font-size: 13px;">--height</tt> are only used for windowed backends, for example ( <a href="https://cgit.kde.org/kwin.git/tree/main_wayland.cpp?h=Plasma/5.17#n420" class="remarkup-link" target="_blank" rel="noreferrer">https://cgit.kde.org/kwin.git/tree/main_wayland.cpp?h=Plasma/5.17#n420</a> ) and some plugins have specific CLI options, like <tt style="background: #ebebeb; font-size: 13px;">--x11-display</tt> for x11-windowed backend or <tt style="background: #ebebeb; font-size: 13px;">--fb-device</tt> for framebuffer backend, <tt style="background: #ebebeb; font-size: 13px;">--wayland-display</tt> for nested wayland. But maybe it's still possible by extending base <tt style="background: #ebebeb; font-size: 13px;">Platform</tt> class even more...</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R108 KWin</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D22418">https://phabricator.kde.org/D22418</a></div></div><br /><div><strong>To: </strong>alexeymin, romangg, KWin<br /><strong>Cc: </strong>PureTryOut, graesslin, kwin, plasma-devel, LeGast00n, The-Feren-OS-Dev, sbergeron, jraleigh, fbampaloukas, GB_2, mkulinski, ragreen, jackyalcine, iodelay, crozbo, bwowk, ZrenBot, ngraham, alexeymin, himcesjf, lesliezhai, ali-mohamed, hardening, romangg, jensreuterberg, abetts, sebas, apol, ahiemstra, mart<br /></div>