kcontrol: drop legacy configuration support in randr KCM

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-03 16:35:42 +02:00
parent 881a427576
commit 609a72aa84
38 changed files with 1771 additions and 3342 deletions

View file

@ -30,12 +30,3 @@ kde4_bool_to_01(X11_xf86misc_FOUND HAVE_XF86MISC) # kcontrol/keyboard
kde4_bool_to_01(X11_XSync_FOUND HAVE_XSYNC) # kwin
kde4_bool_to_01(X11_XRes_FOUND HAVE_XRES) # ksysguard
kde4_bool_to_01(X11_dpms_FOUND HAVE_DPMS) # kscreensaver
cmake_reset_check_state()
set(CMAKE_REQUIRED_INCLUDES ${X11_Xrandr_INCLUDE_PATH})
set(CMAKE_REQUIRED_LIBRARIES ${X11_Xrandr_LIB})
check_function_exists(XRRGetScreenSizeRange XRANDR_1_2_FOUND)
kde4_bool_to_01(XRANDR_1_2_FOUND HAS_RANDR_1_2)
check_function_exists(XRRGetScreenResourcesCurrent XRANDR_1_3_FOUND)
kde4_bool_to_01(XRANDR_1_3_FOUND HAS_RANDR_1_3)
cmake_reset_check_state()

View file

@ -1,12 +1,6 @@
/* Define if you have the XRandR extension */
#cmakedefine HAVE_XRANDR 1
/* Define if you have XRandR 1.2 */
#cmakedefine HAS_RANDR_1_2 1
/* Define if you have XRandR 1.3 */
#cmakedefine HAS_RANDR_1_3 1
/* Define if you have the XDamage extension */
#cmakedefine HAVE_XDAMAGE 1

View file

@ -1,9 +1,7 @@
if( XRANDR_1_2_FOUND )
add_subdirectory(module)
endif( XRANDR_1_2_FOUND )
add_subdirectory(module)
include_directories( ${X11_Xrandr_INCLUDE_PATH} )
include_directories(${X11_Xrandr_INCLUDE_PATH})
########### next target ###############
@ -13,49 +11,65 @@ set(randrinternal_PART_SRCS
randr.cpp
randrdisplay.cpp
collapsiblewidget.cpp
legacyrandrscreen.cpp)
if( XRANDR_1_2_FOUND )
set(randrinternal_PART_SRCS ${randrinternal_PART_SRCS} layoutmanager.cpp
outputconfig.cpp outputgraphicsitem.cpp randrconfig.cpp randrcrtc.cpp
randrmode.cpp randroutput.cpp randrscreen.cpp)
endif( XRANDR_1_2_FOUND )
layoutmanager.cpp
outputconfig.cpp
outputgraphicsitem.cpp
randrconfig.cpp
randrcrtc.cpp
randrmode.cpp
randroutput.cpp
randrscreen.cpp)
set(kcm_randr_PART_SRCS
krandrmodule.cpp
legacyrandrconfig.cpp
${randrinternal_PART_SRCS}
legacyrandrconfigbase.ui
krandrmodule.cpp
randrconfigbase.ui
outputconfigbase.ui
)
kde4_add_plugin(kcm_randr ${kcm_randr_PART_SRCS})
target_link_libraries(kcm_randr ${KDE4_KDEUI_LIBS} ${X11_Xrandr_LIB} ${X11_LIBRARIES})
install(TARGETS kcm_randr DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
target_link_libraries(kcm_randr
${KDE4_KDEUI_LIBS}
${X11_Xrandr_LIB}
${X11_LIBRARIES}
)
install(
TARGETS kcm_randr
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
########### next target ###############
set(krandrtray_SRCS
${randrinternal_PART_SRCS}
main.cpp
krandrtray.cpp
krandrapp.cpp
krandrpassivepopup.cpp
${randrinternal_PART_SRCS}
)
add_executable(krandrtray ${krandrtray_SRCS})
target_link_libraries(krandrtray ${KDE4_KCMUTILS_LIBS} ${X11_Xrandr_LIB} ${X11_LIBRARIES})
target_link_libraries(krandrtray
${KDE4_KCMUTILS_LIBS}
${X11_Xrandr_LIB}
${X11_LIBRARIES}
)
install(TARGETS krandrtray ${INSTALL_TARGETS_DEFAULT_ARGS})
install(
TARGETS krandrtray ${INSTALL_TARGETS_DEFAULT_ARGS}
)
########### next target ###############
install(PROGRAMS krandrstartup DESTINATION ${KDE4_BIN_INSTALL_DIR})
install(
FILES randr.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(FILES randr.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})
install(PROGRAMS krandrtray.desktop DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR})
install(
PROGRAMS krandrtray.desktop
DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR}
)

View file

@ -73,7 +73,7 @@ void ArrowButton::paintEvent( QPaintEvent *event )
class CollapsibleWidget::Private
{
public:
public:
QGridLayout *gridLayout;
QWidget *innerWidget;
ClickableLabel *label;
@ -85,7 +85,7 @@ class CollapsibleWidget::Private
class SettingsContainer::Private
{
public:
public:
QVBoxLayout *layout;
};
@ -143,8 +143,7 @@ void CollapsibleWidget::init()
d->expanderLayout = 0;
d->timeline = new QTimeLine( 150, this );
d->timeline->setEasingCurve( QEasingCurve(QEasingCurve::InOutSine) );
connect( d->timeline, SIGNAL(valueChanged(qreal)),
this, SLOT(animateCollapse(qreal)) );
connect( d->timeline, SIGNAL(valueChanged(qreal)), this, SLOT(animateCollapse(qreal)) );
d->innerWidget = 0;
d->gridLayout = new QGridLayout( this );
@ -154,18 +153,15 @@ void CollapsibleWidget::init()
d->colButton->setCheckable(true);
d->label = new ClickableLabel;
d->label->setSizePolicy(QSizePolicy::MinimumExpanding,
QSizePolicy::Preferred);
d->label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
d->gridLayout->addWidget(d->colButton, 1, 1);
d->gridLayout->addWidget(d->label, 1, 2);
connect(d->label, SIGNAL(clicked()),
d->colButton, SLOT(click()));
connect(d->label, SIGNAL(clicked()), d->colButton, SLOT(click()));
connect(d->colButton, SIGNAL(toggled(bool)),
SLOT(setExpanded(bool)));
connect(d->colButton, SIGNAL(toggled(bool)), SLOT(setExpanded(bool)));
setExpanded(false);
setEnabled(false);
@ -248,10 +244,10 @@ void CollapsibleWidget::setExpanded(bool expanded)
d->innerWidget->setVisible( expanded );
#endif
d->colButton->setChecked( expanded );
d->timeline->setDirection( expanded ? QTimeLine::Forward
: QTimeLine::Backward );
if (d->timeline->state() != QTimeLine::Running)
d->timeline->setDirection( expanded ? QTimeLine::Forward : QTimeLine::Backward );
if (d->timeline->state() != QTimeLine::Running) {
d->timeline->start();
}
}
void CollapsibleWidget::animateCollapse( qreal showAmount )
@ -275,5 +271,4 @@ bool CollapsibleWidget::isExpanded() const
return d->colButton->isChecked();
}
#include "moc_collapsiblewidget.cpp"

View file

@ -33,28 +33,26 @@
class ClickableLabel : public QLabel
{
Q_OBJECT
public:
public:
ClickableLabel( QWidget* parent = 0 );
~ClickableLabel();
void mouseReleaseEvent( QMouseEvent *e );
signals:
signals:
void clicked();
};
class ArrowButton : public QAbstractButton
{
public:
public:
ArrowButton(QWidget *parent = 0);
~ArrowButton();
QSize sizeHint() const { return QSize(16, 16); }
protected:
protected:
void paintEvent( QPaintEvent* );
private:
};
/**
@ -64,7 +62,7 @@ class ArrowButton : public QAbstractButton
class Q_GUI_EXPORT CollapsibleWidget : public QWidget
{
Q_OBJECT
public:
public:
CollapsibleWidget(QWidget *parent = 0);
explicit CollapsibleWidget(const QString& caption, QWidget *parent = 0);
~CollapsibleWidget();
@ -75,23 +73,20 @@ class Q_GUI_EXPORT CollapsibleWidget : public QWidget
QWidget* innerWidget() const;
void setInnerWidget( QWidget *w);
public slots:
public slots:
void setExpanded(bool collapsed);
void setCaption(const QString& caption);
protected:
protected:
void init();
private slots:
private slots:
void animateCollapse(qreal);
private:
private:
Q_DISABLE_COPY( CollapsibleWidget )
class Private;
Private *d;
};
@ -104,20 +99,18 @@ class Q_GUI_EXPORT SettingsContainer : public QScrollArea
{
Q_ENUMS( CollapseState )
Q_OBJECT
public:
public:
enum CollapseState { Collapsed, Uncollapsed };
SettingsContainer( QWidget *parent = 0 );
~SettingsContainer();
CollapsibleWidget* insertWidget( QWidget* w, const QString& name );
private:
private:
Q_DISABLE_COPY( SettingsContainer )
class Private;
Private *d;
};
#endif // COLLAPSIBLEWIDGET_H

View file

@ -22,13 +22,8 @@
#include <config-X11.h>
#include "krandrapp.h"
#include "moc_krandrapp.cpp"
#include "krandrtray.h"
#ifdef HAS_RANDR_1_2
#include "randrscreen.h"
#endif
#include "legacyrandrscreen.h"
#include <X11/Xlib.h>
KRandRApp::KRandRApp()
@ -45,9 +40,9 @@ KRandRApp::KRandRApp()
bool KRandRApp::x11EventFilter(XEvent* e)
{
if (m_display->canHandle(e))
if (m_display->canHandle(e)) {
m_display->handleEvent(e);
}
return KApplication::x11EventFilter(e);
}

View file

@ -29,7 +29,6 @@ class RandRDisplay;
class KRandRApp : public KUniqueApplication
{
Q_OBJECT
public:
KRandRApp();
@ -40,4 +39,4 @@ private:
RandRDisplay *m_display;
};
#endif
#endif // KRANDRAPP_H

View file

@ -18,8 +18,6 @@
*/
#include "krandrmodule.h"
#include "legacyrandrconfig.h"
#include "legacyrandrscreen.h"
#include "randrdisplay.h"
#include "randrconfig.h"
@ -42,7 +40,6 @@ extern "C"
{
KDE_EXPORT void kcminit_randr()
{
// TODO: drop legacy config support
KConfig config("krandrrc");
KConfigGroup group = config.group("Display");
const bool applyonstartup = group.readEntry("ApplyOnStartup", false);
@ -64,11 +61,9 @@ KRandRModule::KRandRModule(QWidget *parent, const QVariantList&)
: KCModule(KSSFactory::componentData(), parent)
{
m_display = new RandRDisplay();
if (!m_display->isValid())
{
if (!m_display->isValid()) {
QVBoxLayout *topLayout = new QVBoxLayout(this);
QLabel *label =
new QLabel(i18n("Your X server does not support resizing and "
QLabel *label = new QLabel(i18n("Your X server does not support resizing and "
"rotating the display. Please update to version 4.3 "
"or greater. You need the X Resize, Rotate, and Reflect "
"extension (RANDR) version 1.1 or greater to use this "
@ -84,22 +79,11 @@ KRandRModule::KRandRModule(QWidget *parent, const QVariantList&)
topLayout->setMargin(0);
topLayout->setSpacing(KDialog::spacingHint());
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
{
m_config = new RandRConfig(this, m_display);
connect(m_config, SIGNAL(changed(bool)), SIGNAL(changed(bool)));
topLayout->addWidget(m_config);
}
else
#endif
{
m_legacyConfig = new LegacyRandRConfig(this, m_display);
connect(m_legacyConfig, SIGNAL(changed(bool)), SIGNAL(changed(bool)));
topLayout->addWidget(m_legacyConfig);
}
//topLayout->addStretch(1);
// topLayout->addStretch(1);
setButtons(KCModule::Apply);
@ -116,12 +100,7 @@ void KRandRModule::defaults()
if (!m_display->isValid()) {
return;
}
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
m_config->defaults();
else
#endif
m_legacyConfig->defaults();
}
void KRandRModule::load()
@ -131,12 +110,7 @@ void KRandRModule::load()
if (!m_display->isValid()) {
return;
}
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
m_config->load();
else
#endif
m_legacyConfig->load();
emit changed(false);
}
@ -146,12 +120,7 @@ void KRandRModule::save()
if (!m_display->isValid()) {
return;
}
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
m_config->save();
else
#endif
m_legacyConfig->save();
}
@ -160,12 +129,7 @@ void KRandRModule::apply()
if (!m_display->isValid()) {
return;
}
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
m_config->apply();
else
#endif
m_legacyConfig->apply();
}
bool KRandRModule::x11Event(XEvent* e)
@ -176,5 +140,4 @@ bool KRandRModule::x11Event(XEvent* e)
return QWidget::x11Event(e);
}
#include "moc_krandrmodule.cpp"

View file

@ -26,13 +26,11 @@
#include <KCModule>
class RandRDisplay;
class LegacyRandRConfig;
class RandRConfig;
class KRandRModule : public KCModule
{
Q_OBJECT
public:
KRandRModule(QWidget *parent, const QVariantList& _args);
~KRandRModule(void);
@ -47,9 +45,8 @@ protected:
void update();
private:
LegacyRandRConfig *m_legacyConfig;
RandRConfig *m_config;
RandRDisplay *m_display;
};
#endif
#endif // KRANDRMODULE_H

View file

@ -31,14 +31,14 @@
KRandrPassivePopup::KRandrPassivePopup( QWidget *parent, Qt::WFlags f )
: KPassivePopup( parent, f )
{
{
update_timer.setSingleShot( true );
connect( &update_timer, SIGNAL(timeout()), SLOT(slotPositionSelf()));
}
}
KRandrPassivePopup* KRandrPassivePopup::message( const QString &caption, const QString &text,
const QPixmap &icon, QWidget *parent, int timeout )
{
{
KRandrPassivePopup *pop = new KRandrPassivePopup( parent );
pop->setAutoDelete( true );
pop->setView( caption, text, icon );
@ -46,33 +46,31 @@ KRandrPassivePopup* KRandrPassivePopup::message( const QString &caption, const Q
pop->show();
pop->startWatchingWidget( parent );
return pop;
}
}
void KRandrPassivePopup::startWatchingWidget( QWidget* widget_P )
{
static Atom wm_state = XInternAtom( QX11Info::display() , "WM_STATE", False );
Window win = widget_P->winId();
bool x11_events = false;
for(;;)
{
for(;;) {
Window root, parent;
Window* children;
unsigned int nchildren;
XQueryTree( QX11Info::display(), win, &root, &parent, &children, &nchildren );
if( children != NULL )
if ( children != NULL ) {
XFree( children );
if( win == root ) // huh?
}
if ( win == root ) { // huh?
break;
}
win = parent;
QWidget* widget = QWidget::find( win );
if( widget != NULL )
{
if( widget != NULL ) {
widget->installEventFilter( this );
watched_widgets.append( widget );
}
else
{
} else {
XWindowAttributes attrs;
XGetWindowAttributes( QX11Info::display(), win, &attrs );
XSelectInput( QX11Info::display(), win, attrs.your_event_mask | StructureNotifyMask );
@ -83,41 +81,44 @@ void KRandrPassivePopup::startWatchingWidget( QWidget* widget_P )
int format;
unsigned long nitems, after;
unsigned char* data;
if( XGetWindowProperty( QX11Info::display(), win, wm_state, 0, 0, False, AnyPropertyType,
&type, &format, &nitems, &after, &data ) == Success )
{
if( data != NULL )
if ( XGetWindowProperty( QX11Info::display(), win, wm_state, 0, 0, False, AnyPropertyType,
&type, &format, &nitems, &after, &data ) == Success ) {
if( data != NULL ) {
XFree( data );
if( type != None ) // toplevel window
}
if( type != None ) { // toplevel window
break;
}
}
if( x11_events )
}
if ( x11_events ) {
kapp->installX11EventFilter( this );
}
}
bool KRandrPassivePopup::eventFilter( QObject* o, QEvent* e )
{
{
if( e->type() == QEvent::Move && o->isWidgetType()
&& watched_widgets.contains( static_cast< QWidget* >( o )))
&& watched_widgets.contains( static_cast< QWidget* >( o ))) {
QTimer::singleShot( 0, this, SLOT(slotPositionSelf()));
return false;
}
return false;
}
bool KRandrPassivePopup::x11Event( XEvent* e )
{
if( e->type == ConfigureNotify && watched_windows.contains( e->xconfigure.window ) )
{
if( !update_timer.isActive() )
{
if( e->type == ConfigureNotify && watched_windows.contains( e->xconfigure.window ) ) {
if( !update_timer.isActive() ) {
update_timer.start( 10 );
}
return false;
}
return KPassivePopup::x11Event( e );
}
}
void KRandrPassivePopup::slotPositionSelf()
{
{
positionSelf();
}
}
#include "moc_krandrpassivepopup.cpp"

View file

@ -29,22 +29,25 @@
class KRandrPassivePopup
: public KPassivePopup
{
{
Q_OBJECT
public:
public:
static KRandrPassivePopup *message( const QString &caption, const QString &text,
const QPixmap &icon, QWidget *parent, int timeout = -1 );
protected:
protected:
virtual bool eventFilter( QObject* o, QEvent* e );
virtual bool x11Event( XEvent* e );
private Q_SLOTS:
private Q_SLOTS:
void slotPositionSelf();
private:
private:
KRandrPassivePopup( QWidget *parent=0, Qt::WFlags f=0 );
void startWatchingWidget( QWidget* w );
QList< QWidget* > watched_widgets;
QList< Window > watched_windows;
QTimer update_timer;
};
};
#endif
#endif // __RANDRPASSIVEPOPUP_H__

View file

@ -1,54 +0,0 @@
#!/bin/sh
#
# A script that is called from startkde. Does early setup of a configuration
# saved by krandr.
if test "$krandrrc_display_applyonstartup" = "true"; then
if test -n "$krandrrc_display_startupcommands"; then
# new way of simply storing the commands
eval "$krandrrc_display_startupcommands"
else
# backwards compatibility
# 4 screens is hopefully enough
for scrn in 0 1 2 3; do
args=
width="\$krandrrc_screen${scrn}_width" ; eval "width=$width"
height="\$krandrrc_screen${scrn}_height" ; eval "height=$height"
if test -n "${width}" -a -n "${height}"; then
args="$args -s ${width}x${height}"
fi
refresh="\$krandrrc_screen${scrn}_refresh" ; eval "refresh=$refresh"
if test -n "${refresh}"; then
args="$args -r ${refresh}"
fi
rotation="\$krandrrc_screen${scrn}_rotation" ; eval "rotation=$rotation"
if test -n "${rotation}"; then
case "${rotation}" in
0)
args="$args -o 0"
;;
90)
args="$args -o 1"
;;
180)
args="$args -o 2"
;;
270)
args="$args -o 3"
;;
esac
fi
reflectx="\$krandrrc_screen${scrn}_reflectx" ; eval "reflectx=$reflectx"
if test "${refrectx}" = "true"; then
args="$args -x"
fi
reflecty="\$krandrrc_screen${scrn}_reflecty" ; eval "reflecty=$reflecty"
if test "${refrecty}" = "true"; then
args="$args -y"
fi
if test -n "$args"; then
xrandr $args
fi
done
fi
fi

View file

@ -22,12 +22,9 @@
#include "krandrtray.h"
#include "krandrpassivepopup.h"
#include "moc_krandrtray.cpp"
#include "legacyrandrscreen.h"
#ifdef HAS_RANDR_1_2
#include "randrscreen.h"
#include "randroutput.h"
#include "randrmode.h"
#endif
#include <QtGui/qevent.h>
#include <QVariant>
@ -62,8 +59,7 @@ KRandRSystemTray::KRandRSystemTray(RandRDisplay *dpy, QWidget* parent)
updateToolTip();
OutputMap outputs = m_display->currentScreen()->outputs();
foreach(RandROutput *output, outputs)
{
foreach(RandROutput *output, outputs) {
connect(output, SIGNAL(outputChanged(RROutput,int)), this, SLOT(slotPrepareMenu()));
connect(output, SIGNAL(outputChanged(RROutput,int)), this, SLOT(updateToolTip()));
}
@ -88,25 +84,17 @@ void KRandRSystemTray::slotPrepareMenu()
m_menu->clear();
if (!m_display->isValid())
{
if (!m_display->isValid()) {
action = m_menu->addAction(i18n("Required X Extension Not Available"));
action->setEnabled(false);
}
else
{
} else {
m_screenPopups.clear();
for (int s = 0; s < m_display->numScreens(); s++)
{
for (int s = 0; s < m_display->numScreens(); s++) {
m_display->setCurrentScreen(s);
if (s == QX11Info::appScreen())
{
if (s == QX11Info::appScreen()) {
/*lastIndex = menu->insertItem(i18n("Screen %1").arg(s+1));
menu->setItemEnabled(lastIndex, false);*/
}
else
{
} else {
KMenu* subMenu = new KMenu(i18n("Screen %1", s+1), m_menu );
subMenu->setObjectName( QString("screen%1").arg(s+1) );
m_screenPopups.append(subMenu);
@ -150,85 +138,72 @@ void KRandRSystemTray::updateToolTip()
const QString icon = "preferences-desktop-display-randr";
QString title = i18n("Display");
QString subTitle = i18n("Resize, rotate and configure screens.");
#ifdef HAS_RANDR_1_2
if (m_display->isValid())
{
if (m_display->isValid()) {
OutputMap outputs = m_display->currentScreen()->outputs();
if (outputs.count() <= 0)
if (outputs.count() <= 0) {
return;
}
RandRScreen *screen = m_display->currentScreen();
Q_ASSERT(screen);
if (screen->outputsUnified() && screen->connectedCount() > 1)
{
if (screen->outputsUnified() && screen->connectedCount() > 1) {
SizeList sizes = screen->unifiedSizes();
if (!sizes.isEmpty())
{
if (!sizes.isEmpty()) {
const QSize currentSize = screen->rect().size();
subTitle = i18n("Resolution: %1 x %2",
QString::number(currentSize.width()),
QString::number(currentSize.height()));
int rotations = screen->unifiedRotations();
if (rotations != RandR::Rotate0)
{
if (rotations != RandR::Rotate0) {
int rotation = RandR::Rotate0;
foreach (RandROutput *output, screen->outputs())
if (output->isActive())
{
foreach (RandROutput *output, screen->outputs()) {
if (output->isActive()) {
rotation = output->rotation();
break;
}
}
if (rotation != RandR::Rotate0)
if (rotation != RandR::Rotate0) {
subTitle += "<br>" + i18n("Rotation: %1", RandR::rotationName(1 << rotation));
}
}
}
else
{
} else {
QString details = "<table>";
bool first = true;
foreach(RandROutput *output, outputs)
{
if (output->isConnected())
{
foreach(RandROutput *output, outputs) {
if (output->isConnected()) {
if (!output->isActive()) {
details += "<tr><td>&nbsp;</td></tr>";
details += "<tr><th align=\"left\" colspan=\"2\">" + output->name()
+ " (" + i18n("Disabled") + ") </th></tr>";
} else {
if (first)
{
if (first) {
first = false;
details += "<tr><td>&nbsp;</td></tr>";
}
else
{
} else {
details += "<tr><td>&nbsp;</td></tr>";
}
details += "<tr><th align=\"left\" colspan=\"2\">" + output->name()
+ "</th></tr>";
QSize currentSize = output->rect().size();
if (output->rotation() & (RandR::Rotate90 | RandR::Rotate270))
if (output->rotation() & (RandR::Rotate90 | RandR::Rotate270)) {
currentSize = QSize(currentSize.height(), currentSize.width());
}
details += "<tr>" + i18n("<td align=\"right\">Resolution: </td><td>%1 x %2</td></tr>",
QString::number(currentSize.width()),
QString::number(currentSize.height()));
RateList rates = output->refreshRates();
if (rates.count())
{
if (rates.count()) {
details += "<tr><td align=\"right\">" + i18n("Refresh: ") + "</td><td>"
+ ki18n("%1 Hz").subs(output->refreshRate(), 0, 'f', 1).toString()
+ "</td></tr>";
}
int rotations = output->rotations();
if (rotations != RandR::Rotate0 &&
output->rotation() != RandR::Rotate0)
{
if (rotations != RandR::Rotate0 && output->rotation() != RandR::Rotate0) {
details += "<tr><td align=\"right\">" + i18n("Rotation: ") + "</td><td>"
+ RandR::rotationName(1 << output->rotation())
+ "</td></tr>";
@ -237,13 +212,11 @@ void KRandRSystemTray::updateToolTip()
}
}
if (details != "<table>")
{
if (details != "<table>") {
subTitle = details + "</table>";
}
}
}
#endif
setToolTip(icon, title, subTitle);
}
@ -254,21 +227,15 @@ void KRandRSystemTray::configChanged()
updateToolTip();
static bool first = true;
if (!first)
{
QString message;
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
if (!first) {
// TODO: display config changed message
message = "Screen config changed";
else
#endif
message = m_display->currentLegacyScreen()->changedMessage();
QString message = "Screen config changed";
KRandrPassivePopup::message(
i18n("Screen configuration has changed"),
message, SmallIcon("view-fullscreen"),
associatedWidget());
associatedWidget()
);
}
first = false;
@ -276,27 +243,23 @@ void KRandRSystemTray::configChanged()
void KRandRSystemTray::populateMenu(KMenu* menu)
{
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
{
QAction *action;
QActionGroup *actionGroup;
OutputMap outputs = m_display->currentScreen()->outputs();
if (outputs.count() <= 0)
if (outputs.count() <= 0) {
return;
}
RandRScreen *screen = m_display->currentScreen();
Q_ASSERT(screen);
// if the outputs are unified, do not show output-specific size
// changing options in the tray.
if (screen->outputsUnified() && screen->connectedCount() > 1)
{
if (screen->outputsUnified() && screen->connectedCount() > 1) {
SizeList sizes = screen->unifiedSizes();
if (sizes.count())
{
if (sizes.count()) {
// populate unified sizes
QSize currentSize;
currentSize = screen->rect().size();
@ -307,40 +270,35 @@ void KRandRSystemTray::populateMenu(KMenu* menu)
// if the outputs are unified, we can rotate the screen on all outputs
int rotations = screen->unifiedRotations();
if (rotations != RandR::Rotate0)
{
if (rotations != RandR::Rotate0) {
menu->addTitle(SmallIcon("view-refresh"), i18n("Orientation"));
int rotation = RandR::Rotate0;
foreach(RandROutput *output, screen->outputs())
if (output->isActive())
{
foreach(RandROutput *output, screen->outputs()) {
if (output->isActive()) {
rotation = output->rotation();
break;
}
}
actionGroup = populateRotations(menu, rotations, rotation);
connect(actionGroup, SIGNAL(triggered(QAction*)), screen, SLOT(slotRotateUnified(QAction*)));
}
}
}
else
{
if (screen->connectedCount() != 1)
} else {
if (screen->connectedCount() != 1) {
menu->addTitle(SmallIcon("view-fullscreen"), i18n("Outputs"));
}
#ifdef HAS_RANDR_1_3
RandROutput *primary = screen->primaryOutput();
#endif //HAS_RANDR_1_3
foreach(RandROutput *output, outputs)
{
if (output->isConnected())
{
foreach(RandROutput *output, outputs) {
if (output->isConnected()) {
KMenu *outputMenu;
if (screen->connectedCount() == 1)
if (screen->connectedCount() == 1) {
outputMenu = menu;
else
} else {
outputMenu = new KMenu(output->name());
}
outputMenu->setIcon(SmallIcon(output->icon()));
outputMenu->addTitle(SmallIcon("view-fullscreen"), i18n("%1 - Screen Size", output->name()));
@ -348,8 +306,9 @@ void KRandRSystemTray::populateMenu(KMenu* menu)
// if the output is rotated 90 or 270, the returned rect is inverted
// so we need to invert the size before comparing
if (output->rotation() & (RandR::Rotate90 | RandR::Rotate270))
if (output->rotation() & (RandR::Rotate90 | RandR::Rotate270)) {
currentSize = QSize(currentSize.height(), currentSize.width());
}
actionGroup = populateSizes(outputMenu, output->sizes(), currentSize);
connect(actionGroup, SIGNAL(triggered(QAction*)), output, SLOT(slotChangeSize(QAction*)));
@ -357,11 +316,9 @@ void KRandRSystemTray::populateMenu(KMenu* menu)
// if there is only one output active, do not show the disable option
// this prevents the user from doing wrong things ;)
kDebug() << "Active outputs: " << screen->activeCount();
if (screen->activeCount() != 1)
{
if (screen->activeCount() != 1) {
action = outputMenu->addAction(i18n("Disable"));
if (!output->crtc())
{
if (!output->crtc()) {
QFont font = action->font();
font.setBold(true);
action->setFont(font);
@ -373,86 +330,45 @@ void KRandRSystemTray::populateMenu(KMenu* menu)
int rotations = output->rotations();
// Don't display the rotation options if there is no point (ie. none are supported)
// XFree86 4.3 does not include rotation support.
if (rotations != RandR::Rotate0)
{
if (rotations != RandR::Rotate0) {
outputMenu->addTitle(SmallIcon("view-refresh"), i18n("Orientation"));
actionGroup = populateRotations(outputMenu, rotations, output->rotation());
connect(actionGroup, SIGNAL(triggered(QAction*)),
output, SLOT(slotChangeRotation(QAction*)));
connect(actionGroup, SIGNAL(triggered(QAction*)), output, SLOT(slotChangeRotation(QAction*)));
}
// refresh rate
RateList rates = output->refreshRates();
if (rates.count())
{
if (rates.count()) {
outputMenu->addTitle(SmallIcon("chronometer"), i18n("Refresh Rate"));
actionGroup = populateRates(outputMenu, rates, output->refreshRate());
connect(actionGroup, SIGNAL(triggered(QAction*)),
output, SLOT(slotChangeRefreshRate(QAction*)));
connect(actionGroup, SIGNAL(triggered(QAction*)), output, SLOT(slotChangeRefreshRate(QAction*)));
}
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3 && screen->connectedCount() != 1)
{
if (screen->connectedCount() != 1) {
outputMenu->addSeparator();
action = outputMenu->addAction(
i18nc("(checkbox) designate this output as the primary output", "Primary output"),
output,
SLOT(slotSetAsPrimary(bool)) );
SLOT(slotSetAsPrimary(bool))
);
action->setCheckable(true);
action->setChecked(primary == output);
}
#endif //HAS_RANDR_1_3
if (screen->connectedCount() != 1)
if (screen->connectedCount() != 1) {
menu->addMenu(outputMenu);
}
}
}
}
// if there is more than one output connected, give the option to unify the outputs
if (screen->connectedCount() != 1 && !screen->unifiedSizes().isEmpty())
{
if (screen->connectedCount() != 1 && !screen->unifiedSizes().isEmpty()) {
menu->addSeparator();
action = menu->addAction( i18n("Unify Outputs"), screen, SLOT(slotUnifyOutputs(bool)) );
action->setCheckable(true);
action->setChecked(screen->outputsUnified());
}
}
else
#endif
populateLegacyMenu(menu);
}
void KRandRSystemTray::populateLegacyMenu(KMenu* menu)
{
menu->addTitle(SmallIcon("view-fullscreen"), i18n("Screen Size"));
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
// add sizes
QActionGroup *screenSizeGroup = populateSizes(menu, RandR::sortSizes(screen->pixelSizes()), screen->currentPixelSize());
connect(screenSizeGroup, SIGNAL(triggered(QAction*)), SLOT(slotResolutionChanged(QAction*)));
// Don't display the rotation options if there is no point (ie. none are supported)
// XFree86 4.3 does not include rotation support.
if (screen->rotations() != RandR::Rotate0)
{
menu->addTitle(SmallIcon("view-refresh"), i18n("Orientation"));
QActionGroup *rotationGroup = populateRotations(menu, screen->rotations(), screen->rotation());
connect(rotationGroup, SIGNAL(triggered(QAction*)), SLOT(slotOrientationChanged(QAction*)));
}
RateList rr = screen->refreshRates(screen->proposedSize());
if (rr.count())
{
menu->addTitle(SmallIcon("clock"), i18n("Refresh Rate"));
QActionGroup *rateGroup = populateRates(menu, rr, screen->refreshRate());
connect(rateGroup, SIGNAL(triggered(QAction*)), SLOT(slotRefreshRateChanged(QAction*)));
}
}
QActionGroup *KRandRSystemTray::populateRotations(KMenu *menu, int rotations, int rotation)
@ -461,17 +377,13 @@ QActionGroup *KRandRSystemTray::populateRotations(KMenu *menu, int rotations, in
QActionGroup *rotateGroup = new QActionGroup(menu);
rotateGroup->setExclusive(true);
for (int i = 0; i < 6; i++)
{
if ((1 << i) & rotations)
{
action = menu->addAction(QIcon(RandR::rotationIcon(1 << i, rotation)),
RandR::rotationName(1 << i));
for (int i = 0; i < 6; i++) {
if ((1 << i) & rotations) {
action = menu->addAction(QIcon(RandR::rotationIcon(1 << i, rotation)), RandR::rotationName(1 << i));
action->setCheckable(true);
action->setData(1 << i);
if (rotation & (1 << i))
{
if (rotation & (1 << i)) {
action->setChecked(true);
}
rotateGroup->addAction(action);
@ -485,14 +397,12 @@ QActionGroup *KRandRSystemTray::populateSizes(KMenu *menu, const SizeList &sizes
QAction *action;
QActionGroup *sizeGroup = new QActionGroup(menu);
sizeGroup->setExclusive(true);
for (int i = 0; i < sizes.count(); ++i)
{
for (int i = 0; i < sizes.count(); ++i) {
QSize s = sizes[i];
action = menu->addAction(QString("%1 x %2").arg(s.width()).arg(s.height()));
action->setCheckable(true);
action->setData(s);
if (s == size)
{
if (s == size) {
action->setChecked(true);
}
sizeGroup->addAction(action);
@ -506,13 +416,11 @@ QActionGroup *KRandRSystemTray::populateRates(KMenu *menu, const RateList &rates
QActionGroup *rateGroup = new QActionGroup(menu);
rateGroup->setExclusive(true);
foreach(float r, rates)
{
foreach(float r, rates) {
action = menu->addAction(ki18n("%1 Hz").subs(r, 0, 'f', 1).toString());
action->setCheckable(true);
action->setData(r);
if (r == rate)
{
if (r == rate) {
action->setChecked(true);
}
rateGroup->addAction(action);
@ -520,86 +428,9 @@ QActionGroup *KRandRSystemTray::populateRates(KMenu *menu, const RateList &rates
return rateGroup;
}
void KRandRSystemTray::slotResolutionChanged(QAction *action)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
QSize s = action->data().toSize();
int index = 0;
const SizeList pixelSizes = screen->pixelSizes();
for (int i = 0; i < pixelSizes.count(); ++i)
if (pixelSizes[i] == s)
{
index = i;
break;
}
if (screen->size() == index)
return;
screen->proposeSize(index);
screen->proposeRefreshRate(-1);
if (screen->applyProposedAndConfirm())
{
KConfig config("krandrrc");
if (m_display->syncTrayApp(config))
screen->save(config);
}
}
void KRandRSystemTray::slotOrientationChanged(QAction *action)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
int propose = screen->rotation();
int rotate = action->data().toInt();
if (rotate & RandR::RotateMask)
propose &= RandR::ReflectMask;
propose ^= rotate;
if (screen->rotation() == propose)
return;
screen->proposeRotation(propose);
if (screen->applyProposedAndConfirm())
{
KConfig config("krandrrc");
if (m_display->syncTrayApp(config))
screen->save(config);
}
}
void KRandRSystemTray::slotRefreshRateChanged(QAction *action)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
int index = action->data().toInt();
if (screen->refreshRate() == index)
return;
screen->proposeRefreshRate(index);
if (screen->applyProposedAndConfirm())
{
KConfig config("krandrrc");
if (m_display->syncTrayApp(config))
screen->save(config);
}
}
void KRandRSystemTray::slotPrefs()
{
if (!m_kcm)
{
if (!m_kcm) {
KCMultiDialog *kcm = new KCMultiDialog( associatedWidget() );
kcm->setFaceType( KCMultiDialog::Plain );
kcm->setWindowTitle( i18n( "Configure Display" ) );

View file

@ -21,13 +21,13 @@
#include <QtGui/qevent.h>
#include <QtCore/qsharedpointer.h>
#include <QAction>
#include <QActionGroup>
#include <KStatusNotifierItem>
#include "randrdisplay.h"
#include <QAction>
#include <QActionGroup>
class KCMultiDialog;
class KHelpMenu;
class KMenu;
@ -35,7 +35,6 @@ class KMenu;
class KRandRSystemTray : public KStatusNotifierItem
{
Q_OBJECT
public:
explicit KRandRSystemTray(RandRDisplay *dpy, QWidget* parent = 0);
~KRandRSystemTray();
@ -45,9 +44,6 @@ public:
protected Q_SLOTS:
void slotScreenActivated();
void slotResolutionChanged(QAction *action);
void slotOrientationChanged(QAction *action);
void slotRefreshRateChanged(QAction *action);
void slotPrefs();
void slotPrepareMenu();
@ -55,7 +51,6 @@ protected Q_SLOTS:
private:
void populateMenu(KMenu* menu);
void populateLegacyMenu(KMenu* menu);
// helper functions
QActionGroup *populateRotations(KMenu *menu, int rotations, int rotation);
@ -69,4 +64,4 @@ private:
QWeakPointer<KCMultiDialog> m_kcm;
};
#endif
#endif // KRANDRTRAY_H

View file

@ -66,8 +66,9 @@ KTimerDialog::KTimerDialog( int msec, TimerStyle style, QWidget *parent,
tStyle = style;
KWindowSystem::setIcons( winId(), DesktopIcon("preferences-desktop-display-randr"), SmallIcon("preferences-desktop-display-randr") );
// default to canceling the dialog on timeout
if ( buttonMask & Cancel )
if ( buttonMask & Cancel ) {
buttonOnTimeout = Cancel;
}
connect( totalTimer, SIGNAL(timeout()), SLOT(slotInternalTimeout()) );
connect( updateTimer, SIGNAL(timeout()), SLOT(slotUpdateTime()) );
@ -124,8 +125,9 @@ void KTimerDialog::setMainWidget( QWidget *widget )
void KTimerDialog::setRefreshInterval( int msec )
{
updateInterval = msec;
if ( updateTimer->isActive() )
if ( updateTimer->isActive() ) {
updateTimer->start( updateInterval );
}
}
int KTimerDialog::timeoutButton() const

View file

@ -27,10 +27,11 @@
#include <kvbox.h>
#include <QTimer>
class KHBox;
#include <QProgressBar>
#include <QLabel>
class KHBox;
/**
* Provides a dialog that is only available for a specified amount
* of time, and reports the time remaining to the user.
@ -48,8 +49,7 @@ class KHBox;
class KTimerDialog : public KDialog
{
Q_OBJECT
public:
public:
/**
* @li @p CountDown - The timer counts downwards from the seconds given.
@ -122,19 +122,19 @@ class KTimerDialog : public KDialog
*/
void setMainWidget( QWidget *widget );
Q_SIGNALS:
Q_SIGNALS:
/**
* Signal which is emitted once the timer has timed out.
*/
void timerTimeout();
public Q_SLOTS:
public Q_SLOTS:
/**
* Execute the dialog modally - see @see QDialog .
*/
int exec();
private Q_SLOTS:
private Q_SLOTS:
/**
* Updates the dialog with the current progress levels.
*/
@ -145,7 +145,7 @@ class KTimerDialog : public KDialog
*/
void slotInternalTimeout();
private:
private:
/**
* Prepares the layout that manages the widgets of the dialog
*/
@ -167,7 +167,4 @@ class KTimerDialog : public KDialog
KTimerDialogPrivate *d;
};
#endif
#endif // _KTIMERDIALOG_H_

View file

@ -27,7 +27,7 @@
#include <math.h>
LayoutManager::LayoutManager(RandRScreen *screen, QGraphicsScene *scene)
: QObject(screen)
: QObject(screen)
{
m_screen = screen;
m_scene = scene;
@ -47,23 +47,21 @@ void LayoutManager::slotAdjustOutput(OutputGraphicsItem *output)
// find the nearest item
QList<QGraphicsItem *> itemList = m_scene->items();
foreach(QGraphicsItem *current, itemList)
{
foreach(QGraphicsItem *current, itemList) {
OutputGraphicsItem *cur = dynamic_cast<OutputGraphicsItem*>(current);
if (cur == output || cur == mouseGrabber)
if (cur == output || cur == mouseGrabber) {
continue;
}
QPointF pos = cur->pos();
float distance = (p.x() - pos.x())*(p.x()-pos.x()) + (p.y() - pos.y())*(p.y() - pos.y());
if (distance <=nearest)
{
if (distance <=nearest) {
nearest = distance;
selected = cur;
}
}
if (selected)
{
if (selected) {
// find in which side this
QRectF s = selected->boundingRect();
QRectF i = output->boundingRect();
@ -78,26 +76,22 @@ void LayoutManager::slotAdjustOutput(OutputGraphicsItem *output)
float right = fabsf(i.right() - s.left());
// choose top
if (top <= bottom && top <= left && top <= right)
{
if (top <= bottom && top <= left && top <= right) {
output->setTop(selected);
selected->setBottom(output);
}
// choose bottom
else if (bottom < top && bottom <= left && bottom <= right)
{
else if (bottom < top && bottom <= left && bottom <= right) {
output->setBottom(selected);
selected->setTop(output);
}
// choose left
else if (left < top && left < bottom && left <= right)
{
else if (left < top && left < bottom && left <= right) {
output->setLeft(selected);
selected->setRight(output);
}
// choose right
else
{
else {
output->setRight(selected);
selected->setLeft(output);
}
@ -120,31 +114,26 @@ void LayoutManager::adjustScene(OutputGraphicsItem *current, QList<OutputGraphic
OutputGraphicsItem *item;
item = current->left();
if (item && visited.indexOf(item) == -1)
{
if (item && visited.indexOf(item) == -1) {
item->setPos(current->x() - item->boundingRect().width(), current->y());
adjustScene(item, visited);
}
item = current->right();
if (item && visited.indexOf(item) == -1)
{
if (item && visited.indexOf(item) == -1) {
item->setPos(current->x() + current->boundingRect().width(), current->y());
adjustScene(item, visited);
}
item = current->top();
if (item && visited.indexOf(item) == -1)
{
if (item && visited.indexOf(item) == -1) {
item->setPos(current->x(), current->y() - item->boundingRect().height());
adjustScene(item, visited);
}
item = current->bottom();
if (item && visited.indexOf(item) == -1)
{
if (item && visited.indexOf(item) == -1) {
item->setPos(current->x(), current->y() + current->boundingRect().height());
adjustScene(item, visited);
}
}

View file

@ -20,10 +20,10 @@
#define __LAYOUTMANAGER_H__
#include <QObject>
#include <QGraphicsScene>
#include "randr.h"
class RandRScreen;
#include <QGraphicsScene>
class OutputGraphicsItem;
class LayoutManager : public QObject
@ -45,4 +45,4 @@ private:
};
#endif
#endif // __LAYOUTMANAGER_H__

View file

@ -1,278 +0,0 @@
/*
* Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
* Copyright (c) 2002 Hamish Rodda <rodda@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "legacyrandrconfig.h"
#include <QRadioButton>
#include "randrdisplay.h"
#include "legacyrandrscreen.h"
LegacyRandRConfig::LegacyRandRConfig(QWidget *parent, RandRDisplay *display)
: QWidget(parent), Ui::LegacyRandRConfigBase()
{
setupUi(this);
layout()->setMargin(0);
m_display = display;
Q_ASSERT(m_display);
if (!m_display->isValid())
return;
for (int s = 0; s < m_display->numScreens(); ++s)
screenCombo->addItem(i18n("Screen %1", s+1));
screenCombo->setCurrentIndex(m_display->currentScreenIndex());
if (m_display->numScreens() <= 1)
screenCombo->setEnabled(false);
new QGridLayout(rotationGroup);
// Create rotations
for (int i = 0; i < RandR::OrientationCount; i++)
addRotationButton(1 << i, i > RandR::RotationCount - 1);
connect(screenCombo, SIGNAL(activated(int)), SLOT(slotScreenChanged(int)));
connect(sizeCombo, SIGNAL(activated(int)), SLOT(slotSizeChanged(int)));
connect(rateCombo, SIGNAL(activated(int)), SLOT(slotRefreshChanged(int)));
connect(applyOnStartup, SIGNAL(clicked()), SLOT(setChanged()));
connect(syncTrayApp, SIGNAL(clicked()), SLOT(setChanged()));
load();
syncTrayApp->setEnabled(applyOnStartup->isChecked());
slotScreenChanged(m_display->currentScreenIndex());
}
LegacyRandRConfig::~LegacyRandRConfig()
{
}
void LegacyRandRConfig::load()
{
if (!m_display->isValid())
return;
// Don't load screen configurations:
// It will be correct already if they wanted to retain their settings over KDE restarts,
// and if it isn't correct they have changed a) their X configuration, b) the screen
// with another program, or c) their hardware.
KConfig config("krandrrc");
m_oldApply = m_display->loadDisplay(config, false);
m_oldSyncTrayApp = m_display->syncTrayApp(config);
applyOnStartup->setChecked(m_oldApply);
syncTrayApp->setChecked(m_oldSyncTrayApp);
setChanged();
}
void LegacyRandRConfig::save()
{
if (!m_display->isValid())
return;
apply();
m_oldApply = applyOnStartup->isChecked();
m_oldSyncTrayApp = syncTrayApp->isChecked();
KConfig config("krandrrc");
m_display->saveDisplay(config, m_oldSyncTrayApp);
if(m_oldApply)
m_display->saveStartup(config);
else
m_display->disableStartup(config);
setChanged();
}
void LegacyRandRConfig::defaults()
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
if (screen->changedFromOriginal()) {
screen->proposeOriginal();
screen->applyProposed();
} else {
screen->proposeOriginal();
}
update();
}
void LegacyRandRConfig::slotScreenChanged(int screenId)
{
m_display->setCurrentScreen(screenId);
// Clear resolutions
sizeCombo->clear();
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
// Add new resolutions
for (int i = 0; i < screen->numSizes(); i++) {
sizeCombo->addItem(QString("%1 x %2").arg(screen->pixelSize(i).width()).arg(screen->pixelSize(i).height()));
// Aspect ratio
/* , aspect ratio %5)*/
/*.arg((double)currentScreen()->size(i).mwidth / (double)currentScreen()->size(i).mheight))*/
}
// configure the possible rotations
for (int i = 0; i < RandR::OrientationCount; i++)
m_rotationGroup.button(1 << i)->setEnabled( (1 << i) & screen->rotations());
m_rotationGroup.button(screen->rotation())->setChecked(true);
populateRefreshRates();
update();
setChanged();
}
void LegacyRandRConfig::slotRotationChanged()
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
//FIXME: need to check this later
int id = m_rotationGroup.checkedId();
screen->proposeRotation(id);
setChanged();
}
void LegacyRandRConfig::slotSizeChanged(int index)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
int oldProposed = screen->proposedSize();
screen->proposeSize(index);
if (screen->proposedSize() != oldProposed) {
screen->proposeRefreshRate(0);
populateRefreshRates();
// Item with index zero is already selected
}
setChanged();
}
void LegacyRandRConfig::slotRefreshChanged(int index)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
screen->proposeRefreshRate(index);
setChanged();
}
void LegacyRandRConfig::setChanged()
{
bool isChanged = (m_oldApply != applyOnStartup->isChecked()) || (m_oldSyncTrayApp != syncTrayApp->isChecked());
syncTrayApp->setEnabled(applyOnStartup->isChecked());
if (!isChanged)
for (int screenIndex = 0; screenIndex < m_display->numScreens(); screenIndex++) {
if (m_display->legacyScreen(screenIndex)->proposedChanged()) {
isChanged = true;
break;
}
}
if (isChanged != m_changed) {
m_changed = isChanged;
emit changed(m_changed);
}
}
void LegacyRandRConfig::apply()
{
if (m_changed) {
m_display->applyProposed();
update();
}
}
void LegacyRandRConfig::update()
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
sizeCombo->blockSignals(true);
sizeCombo->setCurrentIndex(screen->proposedSize());
sizeCombo->blockSignals(false);
m_rotationGroup.blockSignals(true);
m_rotationGroup.button(screen->proposedRotation())->setChecked(true);
//m_rotationGroup.button(4)->setDown(screen->proposedRotation() & RandR::ReflectX);
//m_rotationGroup.button(5)->setDown(screen->proposedRotation() & RandR::ReflectY);
m_rotationGroup.blockSignals(false);
rateCombo->blockSignals(true);
rateCombo->setCurrentIndex(screen->proposedRefreshRate());
rateCombo->blockSignals(false);
}
void LegacyRandRConfig::addRotationButton(int thisRotation, bool checkbox)
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
if (!checkbox) {
QRadioButton* thisButton = new QRadioButton(RandR::rotationName(thisRotation), rotationGroup);
m_rotationGroup.addButton( thisButton, thisRotation );
thisButton->setEnabled(thisRotation & screen->rotations());
connect(thisButton, SIGNAL(clicked()), SLOT(slotRotationChanged()));
rotationGroup->layout()->addWidget(thisButton);
} else {
QCheckBox* thisButton = new QCheckBox(RandR::rotationName(thisRotation), rotationGroup);
m_rotationGroup.addButton( thisButton, thisRotation );
thisButton->setEnabled(thisRotation & screen->rotations());
connect(thisButton, SIGNAL(clicked()), SLOT(slotRotationChanged()));
rotationGroup->layout()->addWidget(thisButton);
}
}
void LegacyRandRConfig::populateRefreshRates()
{
LegacyRandRScreen *screen = m_display->currentLegacyScreen();
Q_ASSERT(screen);
rateCombo->clear();
RateList rr = screen->refreshRates(screen->proposedSize());
rateCombo->setEnabled(rr.count());
foreach(float rate, rr)
{
rateCombo->addItem(ki18n("%1 Hz").subs(rate, 0, 'f', 1).toString(), rate);
}
}
#include "moc_legacyrandrconfig.cpp"

View file

@ -1,65 +0,0 @@
/*
* Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
* Copyright (c) 2002 Hamish Rodda <rodda@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __LEGACYRANDRCONFIG_H__
#define __LEGACYRANDRCONFIG_H__
#include <QButtonGroup>
#include <QWidget>
#include "ui_legacyrandrconfigbase.h"
class RandRDisplay;
class LegacyRandRConfig : public QWidget, public Ui::LegacyRandRConfigBase
{
Q_OBJECT
public:
LegacyRandRConfig(QWidget *parent, RandRDisplay *display);
virtual ~LegacyRandRConfig();
void load();
void save();
void defaults();
void apply();
void update();
protected Q_SLOTS:
void slotScreenChanged(int screen);
void slotRotationChanged();
void slotSizeChanged(int index);
void slotRefreshChanged(int index);
void setChanged();
signals:
void changed(bool c);
protected:
void addRotationButton(int thisRotation, bool checkbox);
void populateRefreshRates();
private:
RandRDisplay *m_display;
bool m_oldApply;
bool m_oldSyncTrayApp;
bool m_changed;
QButtonGroup m_rotationGroup;
};
#endif

View file

@ -1,145 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LegacyRandRConfigBase</class>
<widget class="QWidget" name="LegacyRandRConfigBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<height>292</height>
</rect>
</property>
<property name="windowTitle">
<string>Screen Resize and Rotate Settings</string>
</property>
<property name="whatsThis">
<string>If this option is enabled, options set by the system tray applet will be saved and loaded when KDE starts instead of being temporary.</string>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="screenLabel">
<property name="text">
<string>Settings for screen:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>screenCombo</cstring>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="screenCombo">
<property name="whatsThis">
<string>The screen whose settings you would like to change can be selected using this drop-down list.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="sizeLabel">
<property name="text">
<string>Screen size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>sizeCombo</cstring>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="sizeCombo">
<property name="whatsThis">
<string>The size, otherwise known as the resolution, of your screen can be selected from this drop-down list.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="rateLabel">
<property name="text">
<string>Refresh rate:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="KComboBox" name="rateCombo">
<property name="whatsThis">
<string>The refresh rate of your screen can be selected from this drop-down list.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="rotationGroup">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="whatsThis">
<string>The options in this section allow you to change the rotation of your screen.</string>
</property>
<property name="title">
<string>Orientation (degrees counterclockwise)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="applyOnStartup">
<property name="whatsThis">
<string>If this option is enabled the size and orientation settings will be used when KDE starts.</string>
</property>
<property name="text">
<string>Apply settings on KDE startup</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="syncTrayApp">
<property name="text">
<string>Allow tray application to change startup settings</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>

View file

@ -1,422 +0,0 @@
/*
* Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
* Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QTimer>
#include <QPixmap>
#include "ktimerdialog.h"
#include <kdebug.h>
#include <klocale.h>
#include <kglobal.h>
#include <kapplication.h>
#include <kiconloader.h>
#include <QtGui/QLabel>
#include <QDesktopWidget>
#include <QtGui/qx11info_x11.h>
#include "legacyrandrscreen.h"
LegacyRandRScreen::LegacyRandRScreen(int screenIndex)
: m_config(0L)
, m_screen(screenIndex)
{
loadSettings();
setOriginal();
}
LegacyRandRScreen::~LegacyRandRScreen()
{
if (m_config)
XRRFreeScreenConfigInfo(m_config);
}
void LegacyRandRScreen::loadSettings()
{
if (m_config)
XRRFreeScreenConfigInfo(m_config);
m_config = XRRGetScreenInfo(QX11Info::display(), rootWindow());
Q_ASSERT(m_config);
Rotation rotation;
m_currentSize = m_proposedSize = XRRConfigCurrentConfiguration(m_config, &rotation);
m_currentRotation = m_proposedRotation = rotation;
m_pixelSizes.clear();
m_mmSizes.clear();
int numSizes;
XRRScreenSize* sizes = XRRSizes(QX11Info::display(), m_screen, &numSizes);
for (int i = 0; i < numSizes; i++) {
m_pixelSizes.append(QSize(sizes[i].width, sizes[i].height));
m_mmSizes.append(QSize(sizes[i].mwidth, sizes[i].mheight));
}
m_rotations = XRRRotations(QX11Info::display(), m_screen, &rotation);
m_currentRefreshRate = m_proposedRefreshRate = refreshRateHzToIndex(m_currentSize, XRRConfigCurrentRate(m_config));
}
void LegacyRandRScreen::setOriginal()
{
m_originalSize = m_currentSize;
m_originalRotation = m_currentRotation;
m_originalRefreshRate = m_currentRefreshRate;
}
bool LegacyRandRScreen::applyProposed()
{
//kDebug() << " size " << (SizeID)proposedSize() << ", rotation " << proposedRotation() << ", refresh " << refreshRateIndexToHz(proposedSize(), proposedRefreshRate());
Status status;
if (proposedRefreshRate() < 0)
status = XRRSetScreenConfig(QX11Info::display(), m_config, rootWindow(), (SizeID)proposedSize(), (Rotation)proposedRotation(), CurrentTime);
else {
if( refreshRateIndexToHz(proposedSize(), proposedRefreshRate()) <= 0 ) {
m_proposedRefreshRate = 0;
}
status = XRRSetScreenConfigAndRate(QX11Info::display(), m_config, rootWindow(), (SizeID)proposedSize(), (Rotation)proposedRotation(), refreshRateIndexToHz(proposedSize(), proposedRefreshRate()), CurrentTime);
}
//kDebug() << "New size: " << WidthOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), screen)) << ", " << HeightOfScreen(ScreenOfDisplay(QPaintDevice::x11AppDisplay(), screen));
if (status == RRSetConfigSuccess) {
m_currentSize = m_proposedSize;
m_currentRotation = m_proposedRotation;
m_currentRefreshRate = m_proposedRefreshRate;
return true;
}
return false;
}
bool LegacyRandRScreen::applyProposedAndConfirm()
{
if (proposedChanged()) {
setOriginal();
if (applyProposed()) {
if (!RandR::confirm()) {
proposeOriginal();
applyProposed();
return false;
}
} else {
return false;
}
}
return true;
}
Window LegacyRandRScreen::rootWindow() const
{
return RootWindow(QX11Info::display(), m_screen);
}
QString LegacyRandRScreen::changedMessage() const
{
if (refreshRate() == -1)
return i18n("New configuration:\nResolution: %1 x %2\nOrientation: %3",
currentPixelSize().width(),
currentPixelSize().height(),
currentRotationDescription());
else
return i18n("New configuration:\nResolution: %1 x %2\nOrientation: %3\nRefresh rate: %4",
currentPixelSize().width(),
currentPixelSize().height(),
currentRotationDescription(),
currentRefreshRateDescription());
}
bool LegacyRandRScreen::changedFromOriginal() const
{
return m_currentSize != m_originalSize || m_currentRotation != m_originalRotation || m_currentRefreshRate != m_originalRefreshRate;
}
void LegacyRandRScreen::proposeOriginal()
{
m_proposedSize = m_originalSize;
m_proposedRotation = m_originalRotation;
m_proposedRefreshRate = m_originalRefreshRate;
}
bool LegacyRandRScreen::proposedChanged() const
{
return m_currentSize != m_proposedSize || m_currentRotation != m_proposedRotation || m_currentRefreshRate != m_proposedRefreshRate;
}
QString LegacyRandRScreen::currentRotationDescription() const
{
QString ret = RandR::rotationName(m_currentRotation & RandR::RotateMask);
if (m_currentRotation != (m_currentRotation & RandR::RotateMask)) {
if (m_currentRotation & RR_Rotate_0)
ret = RandR::rotationName(m_currentRotation & (RR_Reflect_X + RR_Reflect_X), true, true);
else
ret += ", " + RandR::rotationName(m_currentRotation & (RR_Reflect_X + RR_Reflect_X), true, false);
}
return ret;
}
int LegacyRandRScreen::rotationIndexToDegree(int rotation) const
{
switch (rotation & RandR::RotateMask) {
case RR_Rotate_90:
return 90;
case RR_Rotate_180:
return 180;
case RR_Rotate_270:
return 270;
default:
return 0;
}
}
int LegacyRandRScreen::rotationDegreeToIndex(int degree) const
{
switch (degree) {
case 90:
return RR_Rotate_90;
case 180:
return RR_Rotate_180;
case 270:
return RR_Rotate_270;
default:
return RR_Rotate_0;
}
}
const QSize& LegacyRandRScreen::currentPixelSize() const
{
return m_pixelSizes[m_currentSize];
}
RateList LegacyRandRScreen::refreshRates(int size) const
{
int nrates;
short* rrates = XRRRates(QX11Info::display(), m_screen, (SizeID)size, &nrates);
RateList rateList;
for (int i = 0; i < nrates; i++)
rateList.append(rrates[i]);
return rateList;
}
QString LegacyRandRScreen::refreshRateDirectDescription(int rate) const
{
return i18nc("Refresh rate in Hertz (Hz)", "%1 Hz", rate);
}
QString LegacyRandRScreen::refreshRateIndirectDescription(int size, int index) const
{
return i18nc("Refresh rate in Hertz (Hz)", "%1 Hz", refreshRateIndexToHz(size, index));
}
QString LegacyRandRScreen::refreshRateDescription(int size, int index) const
{
return ki18n("%1 Hz").subs(refreshRates(size)[index], 0, 'f', 1).toString();
}
bool LegacyRandRScreen::proposeRefreshRate(int index)
{
if (index >= 0 && (int)refreshRates(proposedSize()).count() > index) {
m_proposedRefreshRate = index;
return true;
}
return false;
}
int LegacyRandRScreen::refreshRate() const
{
return m_currentRefreshRate;
}
QString LegacyRandRScreen::currentRefreshRateDescription() const
{
return refreshRateIndirectDescription(m_currentSize, m_currentRefreshRate);
}
int LegacyRandRScreen::proposedRefreshRate() const
{
return m_proposedRefreshRate;
}
int LegacyRandRScreen::refreshRateHzToIndex(int size, int hz) const
{
int nrates;
short* rates = XRRRates(QX11Info::display(), m_screen, (SizeID)size, &nrates);
for (int i = 0; i < nrates; i++)
if (hz == rates[i])
return i;
if (nrates != 0)
// Wrong input Hz!
Q_ASSERT(false);
return -1;
}
int LegacyRandRScreen::refreshRateIndexToHz(int size, int index) const
{
int nrates;
short* rates = XRRRates(QX11Info::display(), m_screen, (SizeID)size, &nrates);
if (nrates == 0 || index < 0)
return 0;
// Wrong input Hz!
if(index >= nrates)
return 0;
return rates[index];
}
int LegacyRandRScreen::numSizes() const
{
return m_pixelSizes.count();
}
const QSize& LegacyRandRScreen::pixelSize(int index) const
{
return m_pixelSizes[index];
}
const QSize& LegacyRandRScreen::mmSize(int index) const
{
return m_mmSizes[index];
}
int LegacyRandRScreen::sizeIndex(const QSize &pixelSize) const
{
for (int i = 0; i < m_pixelSizes.count(); i++)
if (m_pixelSizes[i] == pixelSize)
return i;
return -1;
}
int LegacyRandRScreen::rotations() const
{
return m_rotations;
}
int LegacyRandRScreen::rotation() const
{
return m_currentRotation;
}
int LegacyRandRScreen::size() const
{
return m_currentSize;
}
int LegacyRandRScreen::proposedRotation() const
{
return m_proposedRotation;
}
void LegacyRandRScreen::proposeRotation(int newRotation)
{
m_proposedRotation = newRotation & RandR::OrientationMask;
}
int LegacyRandRScreen::proposedSize() const
{
return m_proposedSize;
}
bool LegacyRandRScreen::proposeSize(int newSize)
{
if ((int)m_pixelSizes.count() > newSize) {
m_proposedSize = newSize;
return true;
}
return false;
}
void LegacyRandRScreen::load(KConfig& config)
{
KConfigGroup group = config.group(QString("Screen%1").arg(m_screen));
if (proposeSize(sizeIndex(group.readEntry("size", currentPixelSize()))))
proposeRefreshRate(refreshRateHzToIndex(proposedSize(), group.readEntry("refresh", refreshRate())));
proposeRotation(rotationDegreeToIndex( group.readEntry("rotation", 0)) +
(group.readEntry("reflectX", false) ? RandR::ReflectX : 0) +
(group.readEntry("reflectY",false) ? RandR::ReflectY : 0));
}
void LegacyRandRScreen::save(KConfig& config) const
{
KConfigGroup group = config.group(QString("Screen%1").arg(m_screen));
group.writeEntry("size", currentPixelSize());
group.writeEntry("refresh", refreshRateIndexToHz(size(), refreshRate()));
group.writeEntry("rotation", rotationIndexToDegree(rotation()));
group.writeEntry("reflectX", (bool)(rotation() & RandR::ReflectMask) == RandR::ReflectX);
group.writeEntry("reflectY", (bool)(rotation() & RandR::ReflectMask) == RandR::ReflectY);
}
QStringList LegacyRandRScreen::startupCommands() const
{
QString command = QString("xrandr -s %1x%2 -r %3 ").arg( currentPixelSize().width(),
currentPixelSize().height(), refreshRateIndexToHz(size(), refreshRate()));
switch( rotation()) {
case RR_Rotate_90:
command += " -o 1 ";
break;
case RR_Rotate_180:
command += " -o 2 ";
break;
case RR_Rotate_270:
command += " -o 3 ";
break;
}
if((rotation() & RandR::ReflectMask) == RandR::ReflectX)
command += " -x ";
if((bool)(rotation() & RandR::ReflectMask) == RandR::ReflectY)
command += " -y ";
return QStringList() << command;
}
int LegacyRandRScreen::pixelCount( int index ) const
{
QSize sz = pixelSize(index);
return sz.width() * sz.height();
}
SizeList LegacyRandRScreen::pixelSizes() const
{
return m_pixelSizes;
}
#include "moc_legacyrandrscreen.cpp"

View file

@ -1,157 +0,0 @@
/*
* Copyright (c) 2007 Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
* Copyright (c) 2002,2003 Hamish Rodda <rodda@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __LEGACYRANDRSCREEN_H__
#define __LEGACYRANDRSCREEN_H__
#include <QObject>
#include <QPixmap>
#include <kcmodule.h>
#include <kconfig.h>
#include "randr.h"
class KTimerDialog;
class LegacyRandRScreen : public QObject
{
Q_OBJECT
public:
LegacyRandRScreen(int screenIndex);
~LegacyRandRScreen();
void loadSettings();
void setOriginal();
bool applyProposed();
/**
* @returns false if the user did not confirm in time, or canceled, or the change failed
*/
bool applyProposedAndConfirm();
Window rootWindow() const;
public:
QString changedMessage() const;
bool changedFromOriginal() const;
void proposeOriginal();
bool proposedChanged() const;
QString currentRotationDescription() const;
int rotationIndexToDegree(int rotation) const;
int rotationDegreeToIndex(int degree) const;
/**
* Refresh rate functions.
*/
RateList refreshRates(int size) const;
QString refreshRateDirectDescription(int rate) const;
QString refreshRateIndirectDescription(int size, int index) const;
QString refreshRateDescription(int size, int index) const;
int refreshRate() const;
QString currentRefreshRateDescription() const;
// Refresh rate hz <==> index conversion
int refreshRateHzToIndex(int size, int hz) const;
int refreshRateIndexToHz(int size, int index) const;
/**
* Screen size functions.
*/
int numSizes() const;
const QSize& pixelSize(int index) const;
const QSize& mmSize(int index) const;
int pixelCount(int index) const;
SizeList pixelSizes() const;
/**
* Retrieve the index of a screen size with a specified pixel size.
*
* @param pixelSize dimensions of the screen in pixels
* @returns the index of the requested screen size
*/
int sizeIndex(const QSize &pixelSize) const;
int rotations() const;
/**
* Current setting functions.
*/
const QSize& currentPixelSize() const;
int rotation() const;
int size() const;
/**
* Proposed setting functions.
*/
int proposedSize() const;
bool proposeSize(int newSize);
int proposedRotation() const;
void proposeRotation(int newRotation);
int proposedRefreshRate() const;
/**
* Propose a refresh rate.
* Please note that you must propose the target size first for this to work.
*
* @param index the index of the refresh rate (not a refresh rate in hz!)
* @returns true if successful, false otherwise.
*/
bool proposeRefreshRate(int index);
/**
* Configuration functions.
*/
void load(KConfig& config);
void save(KConfig& config) const;
QStringList startupCommands() const;
private:
XRRScreenConfiguration* m_config;
int m_screen;
SizeList m_pixelSizes;
SizeList m_mmSizes;
int m_rotations;
int m_originalRotation;
int m_originalSize;
int m_originalRefreshRate;
int m_currentRotation;
int m_currentSize;
int m_currentRefreshRate;
int m_proposedRotation;
int m_proposedSize;
int m_proposedRefreshRate;
};
#endif

View file

@ -28,6 +28,7 @@
#include "krandrapp.h"
static const char krandrtrayVersion[] = "0.5";
int main(int argc, char **argv)
{
KAboutData aboutData("display-randr", "krandr", ki18n("Resize and Rotate"), krandrtrayVersion,

View file

@ -1,4 +1,7 @@
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/.. )
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_BINARY_DIR}/..
)
########### next target ###############
@ -10,16 +13,26 @@ set(kded_randrmonitor_PART_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../randrcrtc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../randrmode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../randr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../legacyrandrscreen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../ktimerdialog.cpp
)
)
kde4_add_plugin(kded_randrmonitor ${kded_randrmonitor_PART_SRCS})
target_link_libraries(kded_randrmonitor ${KDE4_KDEUI_LIBS} ${X11_Xrandr_LIB} ${X11_LIBRARIES} ${KDE4_SOLID_LIBS})
target_link_libraries(kded_randrmonitor
${KDE4_KDEUI_LIBS}
${KDE4_SOLID_LIBS}
${X11_Xrandr_LIB}
${X11_LIBRARIES}
)
install(TARGETS kded_randrmonitor DESTINATION ${KDE4_PLUGIN_INSTALL_DIR} )
install(
TARGETS kded_randrmonitor
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
########### install files ###############
install( FILES randrmonitor.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded )
install(
FILES randrmonitor.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded
)

View file

@ -84,7 +84,6 @@ signals:
void optionChanged();
void connectedChanged(bool);
private:
static bool isRelativeTo( QRect rect, QRect to, Relation rel );
bool m_changed;
@ -98,5 +97,4 @@ private:
OutputConfigList precedingOutputConfigs;
};
#endif
#endif // __OUTPUTCONFIG_H__

View file

@ -66,9 +66,6 @@ private:
OutputConfig *m_config;
QGraphicsTextItem *m_text;
};
#endif
#endif // OUTPUTGRAPHICSITEM_H

View file

@ -20,8 +20,6 @@
#include "randr.h"
#include <KIconLoader>
bool RandR::has_1_2 = false;
bool RandR::has_1_3 = false;
Time RandR::timestamp = 0;
QString RandR::rotationName(int rotation, bool pastTense, bool capitalised)

View file

@ -39,7 +39,6 @@ extern "C"
#include <fixx11h.h>
#ifdef HAS_RANDR_1_2
class RandRScreen;
class RandRCrtc;
class RandROutput;
@ -55,19 +54,13 @@ typedef QList<RandRScreen*> ScreenList;
typedef QList<RROutput> OutputList;
typedef QList<RRCrtc> CrtcList;
typedef QList<RRMode> ModeList;
#endif
typedef QList<float> RateList;
typedef QList<QSize> SizeList;
class LegacyRandRScreen;
typedef QList<LegacyRandRScreen*> LegacyScreenList;
class RandR
{
public:
static bool has_1_2;
static bool has_1_3;
static Time timestamp;
static const int OrientationCount = 6;
@ -85,8 +78,7 @@ public:
OrientationMask = (RotateMask | ReflectMask)
};
enum Changes
{
enum Changes {
ChangeCrtc = 0x01,
ChangeOutputs = 0x02,
ChangeMode = 0x04,

View file

@ -77,18 +77,8 @@ RandRConfig::RandRConfig(QWidget *parent, RandRDisplay *display)
QSizePolicy::Minimum);
layout->addWidget(m_container);
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3)
{
primaryDisplayBox->setVisible(true);
label->setVisible(true);
}
else
#endif //HAS_RANDR_1_3
{
primaryDisplayBox->setVisible(false);
label->setVisible(false);
}
KConfig config("krandrrc");
if (config.hasGroup("Screen_0") && config.group("Screen_0").readEntry("OutputsUnified", false)) {
@ -120,33 +110,25 @@ void RandRConfig::load(void)
m_configs.clear(); // objects deleted above
OutputMap outputs = m_display->currentScreen()->outputs();
#ifdef HAS_RANDR_1_3
RandROutput *primary = m_display->currentScreen()->primaryOutput();
if (RandR::has_1_3)
{
// disconnect while we repopulate the combo box
disconnect(primaryDisplayBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
disconnect(primaryDisplayBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePrimaryDisplay()));
primaryDisplayBox->clear();
primaryDisplayBox->addItem(i18nc("No display selected", "None"));
}
#endif //HAS_RANDR_1_3
// FIXME: adjust it to run on a multi screen system
CollapsibleWidget *w;
OutputGraphicsItem *o;
OutputConfigList preceding;
foreach(RandROutput *output, outputs)
{
foreach(RandROutput *output, outputs) {
OutputConfig *config = new OutputConfig(this, output, preceding, unifyOutputs->isChecked());
m_configs.append( config );
preceding.append( config );
QString description = output->isConnected()
? i18n("%1 (Connected)", output->name())
: output->name();
QString description = output->isConnected() ? i18n("%1 (Connected)", output->name()) : output->name();
w = m_container->insertWidget(config, description);
if(output->isConnected()) {
if (output->isConnected()) {
w->setExpanded(true);
kDebug() << "Output rect:" << output->rect();
}
@ -156,30 +138,20 @@ void RandRConfig::load(void)
o = new OutputGraphicsItem(config);
m_scene->addItem(o);
connect(o, SIGNAL(itemChanged(OutputGraphicsItem*)),
this, SLOT(slotAdjustOutput(OutputGraphicsItem*)));
connect(o, SIGNAL(itemChanged(OutputGraphicsItem*)), this, SLOT(slotAdjustOutput(OutputGraphicsItem*)));
connect(config, SIGNAL(updateView()), this, SLOT(slotUpdateView()));
connect(config, SIGNAL(optionChanged()), this, SIGNAL(changed()));
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3 && output->isConnected())
{
if (output->isConnected()) {
primaryDisplayBox->addItem(output->name(), QVariant::fromValue(output->id()));
if (primary == output)
{
if (primary == output) {
primaryDisplayBox->setCurrentIndex(primaryDisplayBox->count()-1);
}
}
#endif //HAS_RANDR_1_3
}
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3)
{
connect(primaryDisplayBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(changed()));
connect(primaryDisplayBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePrimaryDisplay()));
}
#endif //HAS_RANDR_1_3
slotUpdateView();
}
@ -187,16 +159,15 @@ void RandRConfig::outputConnectedChanged(bool connected)
{
OutputConfig *config = static_cast <OutputConfig *> (sender());
int index = m_configs.indexOf(config);
QString description = connected
? i18n("%1 (Connected)", config->output()->name())
: config->output()->name();
QString description = connected ? i18n("%1 (Connected)", config->output()->name()) : config->output()->name();
m_outputList.at(index)->setCaption(description);
}
void RandRConfig::save()
{
if (!m_display->isValid())
if (!m_display->isValid()) {
return;
}
KConfig config("krandrrc");
if (config.hasGroup("Screen_0")) {
@ -220,19 +191,21 @@ void RandRConfig::apply()
bool first = true;
foreach(CollapsibleWidget *w, m_outputList) {
OutputConfig *config = static_cast<OutputConfig *>(w->innerWidget());
if( config->isActive()) {
if ( config->isActive()) {
QPoint pos = config->position();
if( first ) {
normalizePos = pos;
first = false;
} else {
if( pos.x() < normalizePos.x())
if( pos.x() < normalizePos.x()) {
normalizePos.setX( pos.x());
if( pos.y() < normalizePos.y())
}
if( pos.y() < normalizePos.y()) {
normalizePos.setY( pos.y());
}
}
}
}
normalizePos = -normalizePos;
kDebug() << "Normalizing positions by" << normalizePos;
@ -240,13 +213,14 @@ void RandRConfig::apply()
OutputConfig *config = static_cast<OutputConfig *>(w->innerWidget());
RandROutput *output = config->output();
if(!output->isConnected())
if (!output->isConnected()) {
continue;
}
QSize res = config->resolution();
if(!res.isNull()) {
if(!config->hasPendingChanges( normalizePos )) {
if (!res.isNull()) {
if (!config->hasPendingChanges( normalizePos )) {
kDebug() << "Ignoring identical config for" << output->name();
continue;
}
@ -271,22 +245,14 @@ void RandRConfig::apply()
output->slotDisable();
}
}
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3)
{
int primaryOutputIndex = primaryDisplayBox->currentIndex();
RandRScreen *screen = m_display->currentScreen();
if (primaryOutputIndex > 0)
{
if (primaryOutputIndex > 0) {
QVariant output = primaryDisplayBox->itemData(primaryOutputIndex);
screen->proposePrimaryOutput(screen->output(output.value<RROutput>()));
}
else
{
} else {
screen->proposePrimaryOutput(0);
}
}
#endif //HAS_RANDR_1_3
m_display->applyProposed();
update();
}
@ -296,8 +262,8 @@ void RandRConfig::updatePrimaryDisplay()
QString primary=primaryDisplayBox->currentText();
foreach( QGraphicsItem* item, m_scene->items()) {
OutputGraphicsItem* itemo = dynamic_cast< OutputGraphicsItem* >( item );
if(itemo && (itemo->objectName()==primary)!=itemo->isPrimary()) {
itemo->setPrimary(itemo->objectName()==primary);
if (itemo && (itemo->objectName() == primary) != itemo->isPrimary()) {
itemo->setPrimary(itemo->objectName() == primary);
}
}
}
@ -310,35 +276,30 @@ void RandRConfig::update()
void RandRConfig::saveStartup()
{
if (!m_display->isValid())
if (!m_display->isValid()) {
return;
}
KConfig config("krandrrc");
m_display->saveStartup(config);
#ifdef HAS_RANDR_1_3
if (RandR::has_1_3)
{
// Add setting the primary screen to the list of commands
KConfigGroup group = config.group("Display");
QStringList commands = group.readEntry("StartupCommands").split("\n");
int primaryOutputIndex = primaryDisplayBox->currentIndex();
if (primaryOutputIndex > 0)
{
if (primaryOutputIndex > 0) {
QString primaryOutput = primaryDisplayBox->itemText(primaryOutputIndex);
commands += QString("xrandr --output %1 --primary")
.arg( KShell::quoteArg( primaryOutput ));
}
else
commands += QString("xrandr --output %1 --primary").arg( KShell::quoteArg( primaryOutput ));
} else {
commands += "xrandr --noprimary";
group.writeEntry("StartupCommands",commands.join("\n"));
}
#endif //HAS_RANDR_1_3
KMessageBox::information( window(), i18n( "Configuration has been set as the desktop default." ));
}
void RandRConfig::disableStartup()
{
if (!m_display->isValid())
if (!m_display->isValid()) {
return;
}
KConfig config("krandrrc");
m_display->disableStartup(config);
KMessageBox::information( window(), i18n( "Default desktop setup has been reset." ));
@ -359,9 +320,8 @@ bool RandRConfig::eventFilter(QObject *obj, QEvent *event)
if ( obj == screenView && event->type() == QEvent::Resize ) {
slotUpdateView();
return false;
} else {
return QWidget::eventFilter(obj, event);
}
return QWidget::eventFilter(obj, event);
}
void RandRConfig::slotAdjustOutput(OutputGraphicsItem *o)
@ -383,16 +343,14 @@ void RandRConfig::slotDelayedUpdateView()
bool first = true;
// updates the graphics view so that all outputs fit inside of it
foreach(OutputConfig *config, m_configs)
{
if (first)
{
foreach(OutputConfig *config, m_configs) {
if (first) {
first = false;
r = config->rect();
}
else
} else {
r = r.united(config->rect());
}
}
// scale the total bounding rectangle for all outputs to fit
// 80% of the containing QGraphicsView
float scaleX = (float)screenView->width() / r.width();
@ -406,9 +364,10 @@ void RandRConfig::slotDelayedUpdateView()
screenView->setSceneRect(r);
foreach( QGraphicsItem* item, m_scene->items()) {
if( OutputGraphicsItem* itemo = dynamic_cast< OutputGraphicsItem* >( item ))
if( OutputGraphicsItem* itemo = dynamic_cast< OutputGraphicsItem* >( item )) {
itemo->configUpdated();
}
}
updatePrimaryDisplay();
screenView->update();
}
@ -419,16 +378,13 @@ void RandRConfig::identifyOutputs()
clearIndicators();
QHash< QPoint, QStringList > ids; // outputs at centers of screens (can be more in case of clone mode)
OutputMap outputs = m_display->currentScreen()->outputs();
foreach(RandROutput *output, outputs)
{
if( !output->isConnected() || output->rect().isEmpty())
foreach(RandROutput *output, outputs) {
if( !output->isConnected() || output->rect().isEmpty()) {
continue;
}
ids[ output->rect().center() ].append( output->name());
}
for( QHash< QPoint, QStringList >::ConstIterator it = ids.constBegin();
it != ids.constEnd();
++it )
{
for( QHash< QPoint, QStringList >::ConstIterator it = ids.constBegin(); it != ids.constEnd(); ++it ) {
QLabel *si = new QLabel(it->join("\n"), NULL, Qt::X11BypassWindowManagerHint);
QFont fnt = KGlobalSettings::generalFont();
fnt.setPixelSize(100);

View file

@ -25,8 +25,8 @@
#include <QWidget>
#include <QTimer>
#include <QGraphicsScene>
class SettingsContainer;
class CollapsibleWidget;
class RandRDisplay;
@ -83,5 +83,4 @@ private:
QTimer compressUpdateViewTimer;
};
#endif
#endif // __RANDRCONFIG_H__

View file

@ -91,4 +91,4 @@ private:
RandRScreen *m_screen;
};
#endif
#endif // __RANDRCRTC_H__

View file

@ -28,10 +28,7 @@
#include <QtGui/qx11info_x11.h>
#include "randrdisplay.h"
#ifdef HAS_RANDR_1_2
#include "randrscreen.h"
#endif
#include "legacyrandrscreen.h"
RandRDisplay::RandRDisplay()
: m_valid(true)
@ -47,18 +44,9 @@ RandRDisplay::RandRDisplay()
int major_version, minor_version;
XRRQueryVersion(m_dpy, &major_version, &minor_version);
m_version = i18n("X Resize and Rotate extension version %1.%2",
major_version,minor_version);
m_version = i18n("X Resize and Rotate extension version %1.%2", major_version, minor_version);
// check if we have the new version of the XRandR extension
RandR::has_1_2 = (major_version > 1 || (major_version == 1 && minor_version >= 2));
RandR::has_1_3 = (major_version > 1 || (major_version == 1 && minor_version >= 3));
if(RandR::has_1_3)
kDebug() << "Using XRANDR extension 1.3 or greater.";
else if(RandR::has_1_2)
kDebug() << "Using XRANDR extension 1.2.";
else kDebug() << "Using legacy XRANDR extension (1.1 or earlier).";
kDebug() << "XRANDR error base: " << m_errorBase;
m_numScreens = ScreenCount(m_dpy);
@ -71,44 +59,14 @@ RandRDisplay::RandRDisplay()
// Q_ASSERT(QApplication::desktop()->numScreens() == ScreenCount(QX11Info::display()));
for (int i = 0; i < m_numScreens; i++) {
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
m_screens.append(new RandRScreen(i));
else
#endif
m_legacyScreens.append(new LegacyRandRScreen(i));
}
#if 0
//#ifdef HAS_RANDR_1_2
// check if we have more than one output, if no, revert to the legacy behavior
if (RandR::has_1_2)
{
int count = 0;
foreach(RandRScreen *screen, m_screens)
count += screen->outputs().count();
if (count < 2)
{
RandR::has_1_2 = false;
for (int i = 0; i < m_numScreens; ++i)
{
delete m_screens[i];
m_legacyScreens.append(new LegacyRandRScreen(i));
}
m_screens.clear();
}
}
#endif
setCurrentScreen(DefaultScreen(QX11Info::display()));
}
RandRDisplay::~RandRDisplay()
{
qDeleteAll(m_legacyScreens);
#ifdef HAS_RANDR_1_2
qDeleteAll(m_screens);
#endif
}
bool RandRDisplay::isValid() const
@ -151,8 +109,9 @@ int RandRDisplay::screenIndexOfWidget(QWidget* widget)
// Xinerama by default, which doesn't work properly with randr.
// It will return more screens than exist for the display, causing
// a crash in the screen/currentScreen methods.
if(widget)
if (widget) {
return widget->x11Info().screen();
}
return -1;
}
@ -173,31 +132,19 @@ bool RandRDisplay::needsRefresh() const
void RandRDisplay::refresh()
{
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2) {
for (int i = 0; i < m_screens.count(); ++i) {
RandRScreen* s = m_screens.at(i);
s->loadSettings();
}
}
else
#endif
{
for (int i = 0; i < m_legacyScreens.size(); ++i) {
LegacyRandRScreen* s = m_legacyScreens.at(i);
s->loadSettings();
}
}
}
bool RandRDisplay::canHandle(const XEvent *e) const
{
if (e->type == m_eventBase + RRScreenChangeNotify)
if (e->type == m_eventBase + RRScreenChangeNotify) {
return true;
#ifdef HAS_RANDR_1_2
else if (e->type == m_eventBase + RRNotify)
} else if (e->type == m_eventBase + RRNotify) {
return true;
#endif
}
return false;
}
@ -205,24 +152,14 @@ bool RandRDisplay::canHandle(const XEvent *e) const
void RandRDisplay::handleEvent(XEvent *e)
{
if (e->type == m_eventBase + RRScreenChangeNotify) {
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2) {
XRRScreenChangeNotifyEvent *event = (XRRScreenChangeNotifyEvent*)(e);
for (int i=0; i < m_screens.count(); ++i) {
RandRScreen *screen = m_screens.at(i);
if (screen->rootWindow() == event->root)
if (screen->rootWindow() == event->root) {
screen->handleEvent(event);
}
}
else
#endif
{
// handle the event
}
}
#ifdef HAS_RANDR_1_2
else if (e->type == m_eventBase + RRNotify) {
} else if (e->type == m_eventBase + RRNotify) {
//forward the event to the right screen
XRRNotifyEvent *event = (XRRNotifyEvent*)e;
for (int i=0; i < m_screens.count(); ++i) {
@ -232,7 +169,6 @@ void RandRDisplay::handleEvent(XEvent *e)
}
}
}
#endif
}
int RandRDisplay::numScreens() const
@ -241,17 +177,6 @@ int RandRDisplay::numScreens() const
return m_numScreens;
}
LegacyRandRScreen* RandRDisplay::legacyScreen(int index)
{
return m_legacyScreens.at(index);
}
LegacyRandRScreen* RandRDisplay::currentLegacyScreen()
{
return m_legacyScreens.at(m_currentScreenIndex);
}
#ifdef HAS_RANDR_1_2
RandRScreen* RandRDisplay::screen(int index)
{
return m_screens.at(index);
@ -261,28 +186,6 @@ RandRScreen* RandRDisplay::currentScreen()
{
return m_screens.at(m_currentScreenIndex);
}
#endif
bool RandRDisplay::loadDisplay(KConfig& config, bool loadScreens)
{
if (loadScreens)
{
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
{
foreach(RandRScreen *s, m_screens)
s->load(config);
}
else
#endif
{
foreach(LegacyRandRScreen* s, m_legacyScreens)
s->load(config);
}
}
return applyOnStartup(config);
}
bool RandRDisplay::applyOnStartup(KConfig& config)
{
@ -294,25 +197,6 @@ bool RandRDisplay::syncTrayApp(KConfig& config)
return config.group("Display").readEntry("SyncTrayApp", false);
}
void RandRDisplay::saveDisplay(KConfig& config, bool syncTrayApp)
{
KConfigGroup group = config.group("Display");
group.writeEntry("SyncTrayApp", syncTrayApp);
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
{
foreach(RandRScreen *s, m_screens)
s->save(config);
}
else
#endif
{
foreach(LegacyRandRScreen *s, m_legacyScreens)
s->save(config);
}
}
// to be used during desktop startup, make all screens provide the shell commands
// (using xrandr cli tool), save them here and a script will perform these commands
// early during desktop startup
@ -321,16 +205,7 @@ void RandRDisplay::saveStartup(KConfig& config)
KConfigGroup group = config.group("Display");
group.writeEntry("ApplyOnStartup", true);
QStringList commands;
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
{
foreach(RandRScreen *s, m_screens)
commands += s->startupCommands();
}
else
#endif
{
foreach(LegacyRandRScreen *s, m_legacyScreens)
foreach(RandRScreen *s, m_screens) {
commands += s->startupCommands();
}
group.writeEntry( "StartupCommands", commands.join( "\n" ));
@ -346,22 +221,8 @@ void RandRDisplay::disableStartup(KConfig& config)
void RandRDisplay::applyProposed(bool confirm)
{
#ifdef HAS_RANDR_1_2
if (RandR::has_1_2)
foreach(RandRScreen *s, m_screens)
foreach(RandRScreen *s, m_screens) {
s->applyProposed(confirm);
else
#endif
{
foreach(LegacyRandRScreen *s, m_legacyScreens)
{
if (s->proposedChanged()) {
if (confirm)
s->applyProposedAndConfirm();
else
s->applyProposed();
}
}
}
}

View file

@ -43,12 +43,8 @@ public:
int screenIndexOfWidget(QWidget* widget);
int numScreens() const;
LegacyRandRScreen* legacyScreen(int index);
LegacyRandRScreen* currentLegacyScreen();
#ifdef HAS_RANDR_1_2
RandRScreen* screen(int index);
RandRScreen* currentScreen();
#endif
void setCurrentScreen(int index);
int currentScreenIndex() const;
@ -59,11 +55,8 @@ public:
* Loads saved settings.
*
* @param config the KConfig object to load from
* @param loadScreens whether to call LegacyRandRScreen::load() for each screen
* @retuns true if the settings should be applied on KDE startup.
*/
bool loadDisplay(KConfig& config, bool loadScreens = true);
void saveDisplay(KConfig& config, bool syncTrayApp);
void saveStartup(KConfig& config);
void disableStartup(KConfig& config);
@ -79,10 +72,7 @@ private:
Display *m_dpy;
int m_numScreens;
int m_currentScreenIndex;
LegacyScreenList m_legacyScreens;
#ifdef HAS_RANDR_1_2
ScreenList m_screens;
#endif
bool m_valid;
QString m_errorCode;
@ -92,4 +82,4 @@ private:
int m_errorBase;
};
#endif
#endif // __RANDRDISPLAY_H__

View file

@ -21,7 +21,6 @@
#include "randr.h"
class RandRMode
{
public:
@ -42,4 +41,4 @@ private:
};
#endif
#endif // __RANDRMODE_H__

View file

@ -23,11 +23,11 @@
#include <QObject>
#include <QString>
#include <QRect>
#include <QAction>
#include "randr.h"
#include "randrmode.h"
#include <QAction>
class KConfig;
/** Class representing an RROutput identifier. This class is used
@ -36,7 +36,6 @@ class KConfig;
class RandROutput : public QObject
{
Q_OBJECT
public:
RandROutput(RandRScreen *parent, RROutput id);
~RandROutput();
@ -139,17 +138,20 @@ signals:
protected:
/** Query Xrandr for information about this output, and set
* up this instance accordingly. */
* up this instance accordingly.
*/
void queryOutputInfo(void);
/** Find the first CRTC that is not controlling any
* display devices. */
* display devices.
*/
RandRCrtc *findEmptyCrtc(void);
bool tryCrtc(RandRCrtc *crtc, int changes);
/** Set the current CRT controller for this output.
* The CRTC should never be set directly; it should be added through
* this function to properly manage signals related to this output. */
* this function to properly manage signals related to this output.
*/
bool setCrtc(RandRCrtc *crtc, bool applyNow = true);
private:
@ -177,5 +179,7 @@ private:
int m_rotations;
bool m_connected;
};
#endif
#endif // __RANDROUTPUT_H__
// vim:noet:sts=8:sw=8:

View file

@ -31,8 +31,7 @@ RandRScreen::RandRScreen(int screenIndex)
m_resources(0)
{
m_index = screenIndex;
m_rect = QRect(0, 0, XDisplayWidth(QX11Info::display(), m_index),
XDisplayHeight(QX11Info::display(), m_index));
m_rect = QRect(0, 0, XDisplayWidth(QX11Info::display(), m_index), XDisplayHeight(QX11Info::display(), m_index));
m_connectedCount = 0;
m_activeCount = 0;
@ -44,10 +43,8 @@ RandRScreen::RandRScreen(int screenIndex)
m_originalPrimaryOutput = primaryOutput();
// select for randr input events
int mask = RRScreenChangeNotifyMask |
RRCrtcChangeNotifyMask |
RROutputChangeNotifyMask |
RROutputPropertyNotifyMask;
int mask = RRScreenChangeNotifyMask | RRCrtcChangeNotifyMask;
mask |= RROutputChangeNotifyMask | RROutputPropertyNotifyMask;
XRRSelectInput(QX11Info::display(), rootWindow(), 0);
XRRSelectInput(QX11Info::display(), rootWindow(), mask);
@ -55,8 +52,9 @@ RandRScreen::RandRScreen(int screenIndex)
RandRScreen::~RandRScreen()
{
if (m_resources)
if (m_resources) {
XRRFreeScreenResources(m_resources);
}
//qDeleteAll(m_crtcs);
//qDeleteAll(m_outputs);
@ -83,8 +81,7 @@ void RandRScreen::loadSettings(bool notify)
bool changed = false;
int minW, minH, maxW, maxH;
Status status = XRRGetScreenSizeRange(QX11Info::display(), rootWindow(),
&minW, &minH, &maxW, &maxH);
Status status = XRRGetScreenSizeRange(QX11Info::display(), rootWindow(), &minW, &minH, &maxW, &maxH);
//FIXME: we should check the status here
Q_UNUSED(status);
QSize minSize = QSize(minW, minH);
@ -180,27 +177,28 @@ void RandRScreen::handleRandREvent(XRRNotifyEvent* event)
// forward events to crtcs and outputs
switch (event->subtype) {
case RRNotify_CrtcChange:
case RRNotify_CrtcChange: {
crtcEvent = (XRRCrtcChangeNotifyEvent*)event;
c = crtc(crtcEvent->crtc);
Q_ASSERT(c);
c->handleEvent(crtcEvent);
return;
case RRNotify_OutputChange:
}
case RRNotify_OutputChange: {
outputEvent = (XRROutputChangeNotifyEvent*)event;
o = output(outputEvent->output);
Q_ASSERT(o);
o->handleEvent(outputEvent);
return;
case RRNotify_OutputProperty:
}
case RRNotify_OutputProperty: {
propertyEvent = (XRROutputPropertyNotifyEvent*)event;
o = output(propertyEvent->output);
Q_ASSERT(o);
o->handlePropertyEvent(propertyEvent);
return;
}
}
}
QSize RandRScreen::minSize() const
@ -220,9 +218,9 @@ CrtcMap RandRScreen::crtcs() const
RandRCrtc* RandRScreen::crtc(RRCrtc id) const
{
if (m_crtcs.contains(id))
if (m_crtcs.contains(id)) {
return m_crtcs[id];
}
return 0;
}
@ -233,22 +231,19 @@ OutputMap RandRScreen::outputs() const
RandROutput* RandRScreen::output(RROutput id) const
{
if (m_outputs.contains(id))
if (m_outputs.contains(id)) {
return m_outputs[id];
}
return 0;
}
#ifdef HAS_RANDR_1_3
void RandRScreen::setPrimaryOutput(RandROutput* output)
{
if (RandR::has_1_3)
{
RROutput id = None;
if (output)
if (output) {
id = output->id();
XRRSetOutputPrimary(QX11Info::display(), rootWindow(), id);
}
XRRSetOutputPrimary(QX11Info::display(), rootWindow(), id);
}
void RandRScreen::proposePrimaryOutput(RandROutput* output)
@ -258,13 +253,8 @@ void RandRScreen::proposePrimaryOutput(RandROutput* output)
RandROutput* RandRScreen::primaryOutput()
{
if (RandR::has_1_3)
{
return output(XRRGetOutputPrimary(QX11Info::display(), rootWindow()));
}
return 0;
}
#endif
ModeMap RandRScreen::modes() const
{
@ -273,8 +263,9 @@ ModeMap RandRScreen::modes() const
RandRMode RandRScreen::mode(RRMode id) const
{
if (m_modes.contains(id))
if (m_modes.contains(id)) {
return m_modes[id];
}
return RandRMode(0);
}
@ -286,40 +277,45 @@ bool RandRScreen::adjustSize(const QRect &minimumSize)
//start with a given minimum rect
QRect rect = QRect(0, 0, 0, 0).united(minimumSize);
foreach(RandROutput *output, m_outputs)
{
foreach(RandROutput *output, m_outputs) {
// outputs that are not active should not be taken into account
// when calculating the screen size
if (!output->isActive())
if (!output->isActive()) {
continue;
}
rect = rect.united(output->rect());
}
// check bounds
if (rect.width() < m_minSize.width())
if (rect.width() < m_minSize.width()) {
rect.setWidth(m_minSize.width());
if (rect.height() < m_minSize.height())
}
if (rect.height() < m_minSize.height()) {
rect.setHeight(m_minSize.height());
if (rect.width() > m_maxSize.width())
}
if (rect.width() > m_maxSize.width()) {
return false;
if (rect.height() > m_maxSize.height())
}
if (rect.height() > m_maxSize.height()) {
return false;
}
return setSize(rect.size());
}
bool RandRScreen::setSize(const QSize &s)
{
if (s == m_rect.size())
if (s == m_rect.size()) {
return true;
}
if (s.width() < m_minSize.width() ||
s.height() < m_minSize.height() ||
s.width() > m_maxSize.width() ||
s.height() > m_maxSize.height())
s.height() > m_maxSize.height()) {
return false;
}
int widthMM, heightMM;
float dpi;
@ -364,19 +360,18 @@ int RandRScreen::unifiedRotations() const
bool first = true;
int rotations = RandR::Rotate0;
foreach(RandRCrtc *crtc, m_crtcs)
{
if (!crtc->connectedOutputs().count())
foreach(RandRCrtc *crtc, m_crtcs) {
if (!crtc->connectedOutputs().count()) {
continue;
}
if (first)
{
if (first) {
rotations = crtc->rotations();
first = false;
}
else
} else {
rotations &= crtc->rotations();
}
}
return rotations;
}
@ -386,29 +381,26 @@ SizeList RandRScreen::unifiedSizes() const
SizeList sizeList;
bool first = true;
foreach(RandROutput *output, m_outputs)
{
if (!output->isConnected())
foreach(RandROutput *output, m_outputs) {
if (!output->isConnected()) {
continue;
}
if (first)
{
if (first) {
// we start using the list from the first output
sizeList = output->sizes();
first = false;
}
else
{
} else {
SizeList outputSizes = output->sizes();
for (int i = sizeList.count() - 1; i >=0; --i)
{
for (int i = sizeList.count() - 1; i >=0; --i) {
// check if the current output has the i-th size of the sizeList
// if not, remove from the list
if (outputSizes.indexOf(sizeList[i]) == -1)
if (outputSizes.indexOf(sizeList[i]) == -1) {
sizeList.removeAt(i);
}
}
}
}
return sizeList;
}
@ -447,11 +439,11 @@ void RandRScreen::save(KConfig &config)
group.writeEntry("UnifiedRect", m_unifiedRect);
group.writeEntry("UnifiedRotation", m_unifiedRotation);
foreach(RandROutput *output, m_outputs)
{
if (output->isConnected())
foreach(RandROutput *output, m_outputs) {
if (output->isConnected()) {
output->save(config);
}
}
}
void RandRScreen::save()
@ -530,12 +522,10 @@ bool RandRScreen::applyProposed(bool confirm)
break;
}
}*/
#ifdef HAS_RANDR_1_3
if (succeed)
{
setPrimaryOutput(m_proposedPrimaryOutput);
}
#endif //HAS_RANDR_1_3
kDebug() << "Changes have been applied to all outputs.";
@ -560,10 +550,8 @@ bool RandRScreen::applyProposed(bool confirm)
}
}
#ifdef HAS_RANDR_1_3
m_proposedPrimaryOutput = m_originalPrimaryOutput;
setPrimaryOutput(m_proposedPrimaryOutput);
#endif //HAS_RANDR_1_3
return false;
}

View file

@ -24,15 +24,14 @@
#include <QtGui/qx11info_x11.h>
#include <QObject>
#include <QMap>
#include <QSize>
#include <QAction>
class KConfig;
class RandRScreen : public QObject
{
Q_OBJECT
public:
RandRScreen(int screenIndex);
~RandRScreen();
@ -56,12 +55,10 @@ public:
OutputMap outputs() const;
RandROutput *output(RROutput id) const;
#ifdef HAS_RANDR_1_3
void setPrimaryOutput(RandROutput* output);
RandROutput* primaryOutput();
void proposePrimaryOutput(RandROutput* output);
#endif
ModeMap modes() const;
RandRMode mode(RRMode id) const;
@ -122,18 +119,16 @@ private:
int m_connectedCount;
int m_activeCount;
#ifdef HAS_RANDR_1_3
RandROutput* m_originalPrimaryOutput;
RandROutput* m_proposedPrimaryOutput;
#endif //HAS_RANDR_1_3
XRRScreenResources* m_resources;
CrtcMap m_crtcs;
OutputMap m_outputs;
ModeMap m_modes;
};
#endif
#endif // __RANDRSCREEN_H__
// vim:noet:sts=8:sw=8: