Commit 4046be3c authored by Xuetian Weng's avatar Xuetian Weng
Browse files

kimpanel: try to workaround some qt/glib issue and fix memory leak

parent a418979b
......@@ -178,30 +178,23 @@ static void initIconMap(QMap<QByteArray, QByteArray>& iconMap)
iconMap["gtk-zoom-out"] = "zoom-out";
}
App::App(int argc, char** argv): QGuiApplication(argc, argv)
App::App(int argc, char* argv[]): QGuiApplication(argc, argv)
,m_eventFilter(new XcbEventFilter)
,m_init(false)
,m_bus(0)
,m_bus(ibus_bus_new ())
,m_impanel(0)
,m_keyboardGrabbed(false)
,m_doGrab(false)
,m_syms(0)
,m_watcher(new QDBusServiceWatcher(this))
{
m_watcher->setConnection(QDBusConnection::sessionBus());
m_watcher->addWatchedService("org.kde.impanel");
connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &App::finalize);
m_syms = xcb_key_symbols_alloc(QX11Info::connection());
installNativeEventFilter(m_eventFilter.data());
ibus_init ();
m_bus = ibus_bus_new ();
g_signal_connect (m_bus, "connected", G_CALLBACK (ibus_connected_cb), this);
g_signal_connect (m_bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), this);
if (ibus_bus_is_connected (m_bus)) {
init();
}
initIconMap(m_iconMap);
m_watcher->setConnection(QDBusConnection::sessionBus());
m_watcher->addWatchedService("org.kde.impanel");
init();
}
uint App::getPrimaryModifier(uint state)
......@@ -302,6 +295,12 @@ void App::init()
if (m_init) {
return;
}
if (!ibus_bus_is_connected (m_bus)) {
return;
}
g_signal_connect (m_bus, "connected", G_CALLBACK (ibus_connected_cb), this);
g_signal_connect (m_bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), this);
connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, &App::finalize);
GDBusConnection* connection = ibus_bus_get_connection (m_bus);
g_dbus_connection_signal_subscribe (connection,
"org.freedesktop.DBus",
......
......@@ -42,17 +42,17 @@ class App : public QGuiApplication {
Q_OBJECT
public:
typedef QPair< uint, uint > TriggerKey;
App(int argc, char** argv);
App(int argc, char* argv[]);
virtual ~App();
void setTriggerKeys(QList< TriggerKey > triggersList);
void setDoGrab(bool doGrab);
bool keyboardGrabbed() { return m_keyboardGrabbed; }
bool nativeEvent(xcb_generic_event_t* event);
void init();
void nameAcquired();
void nameLost();
QByteArray normalizeIconName(const QByteArray& icon) const;
public Q_SLOTS:
void init();
void finalize();
void clean();
void grabKey();
......
......@@ -19,19 +19,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QSessionManager>
#include <ibus.h>
#include <stdlib.h>
#include <locale.h>
#include "panel.h"
#include "app.h"
#define _UNUSED(x) ((void) x)
int
main (int argc, char **argv)
main (int argc, char *argv[])
{
ibus_init ();
// we don't need im in this.
qputenv("QT_IM_MODULE", "compose");
App app(argc, argv);
QGuiApplication::setFallbackSessionManagementEnabled(false);
auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
return app.exec();
}
......@@ -169,15 +169,18 @@ void ibus_panel_impanel_navigate(IBusPanelImpanel* impanel, gboolean start, gboo
engine_desc = ibus_bus_get_global_engine(impanel->bus);
} else if (static_cast<size_t>(impanel->selected) < impanel->engineManager->length()) {
engine_desc = impanel->engineManager->engines()[impanel->selected];
g_object_ref(engine_desc);
}
if (!engine_desc) {
engine_desc = impanel->engineManager->engines()[0];
g_object_ref(engine_desc);
}
if (engine_desc) {
const char* name = impanel->engineManager->navigate(engine_desc, forward);
impanel->selected = impanel->engineManager->getIndexByName(name);
g_object_unref(engine_desc);
} else {
return;
}
......@@ -532,15 +535,14 @@ impanel_update_engines_order(IBusPanelImpanel* impanel, GVariant* var_engines) {
const gchar** engine_names = NULL;
size_t len = 0;
engine_names = g_variant_get_strv(var_engines, &len);
if (len == 0) {
return;
}
impanel->engineManager->setOrder(engine_names, len);
if (len) {
impanel->engineManager->setOrder(engine_names, len);
if (impanel->engineManager->engines()) {
ibus_bus_set_global_engine(impanel->bus, ibus_engine_desc_get_name(impanel->engineManager->engines()[0]));
if (impanel->engineManager->engines()) {
ibus_bus_set_global_engine(impanel->bus, ibus_engine_desc_get_name(impanel->engineManager->engines()[0]));
}
}
g_free(engine_names);
}
static void
......@@ -591,6 +593,7 @@ impanel_update_latin_layouts(IBusPanelImpanel* impanel, GVariant* variant) {
const gchar** variants = g_variant_get_strv(variant, &length);
impanel->xkbLayoutManager->setLatinLayouts(variants, length);
g_free(variants);
}
static void
......@@ -664,6 +667,7 @@ impanel_set_engine(IBusPanelImpanel* impanel, const char* name)
if (engine_desc) {
impanel->xkbLayoutManager->setLayout(engine_desc);
}
g_object_unref(engine_desc);
}
impanel->engineManager->setCurrentEngine(name);
} else {
......@@ -1053,6 +1057,7 @@ ibus_panel_impanel_focus_in (IBusPanelService *panel,
IBusEngineDesc *engine_desc = ibus_bus_get_global_engine(impanel->bus);
impanel_update_logo_by_engine(impanel, engine_desc);
g_object_unref(engine_desc);
impanel->engineManager->setCurrentContext(input_context_path);
if (!impanel->engineManager->useGlobalEngine()) {
......@@ -1099,13 +1104,12 @@ ibus_panel_impanel_real_register_properties(IBusPanelImpanel* impanel)
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
IBusEngineDesc* engine_desc = NULL;
if (impanel->selected >= 0 && static_cast<size_t>(impanel->selected) < impanel->engineManager->length()) {
engine_desc = impanel->engineManager->engines()[impanel->selected];
auto engine_desc = impanel->engineManager->engines()[impanel->selected];
QByteArray propstr = ibus_engine_desc_to_logo_propstr(engine_desc);
g_variant_builder_add (&builder, "s", propstr.constData());
} else {
engine_desc = ibus_bus_get_global_engine(impanel->bus);
auto engine_desc = ibus_bus_get_global_engine(impanel->bus);
QByteArray propstr = ibus_engine_desc_to_logo_propstr(engine_desc);
g_variant_builder_add (&builder, "s", propstr.constData());
......@@ -1117,6 +1121,7 @@ ibus_panel_impanel_real_register_properties(IBusPanelImpanel* impanel)
++i;
}
}
g_object_unref(engine_desc);
}
g_dbus_connection_emit_signal (impanel->conn,
......@@ -1477,6 +1482,7 @@ ibus_panel_impanel_state_changed (IBusPanelService *panel)
ibus_config_set_value(config, "general", "engines-order", var);
}
g_strfreev(engine_names);
g_object_unref(engine_desc);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment